In this video course you will learn how to create a simple Laravel Package.
1. Creating and Initializing the Package Folders
The first steps in creating your new package are pretty simple. You will want to add a new folder called packages to your application. Inside that folder you will add your vendor folder and in the vendor folder you will create your package folder. The vendor folder could be the name of your business or the name of your project.
In this introduction video you will learn how to create the folder structure for your new package. We'll also initialize the folder as a composer repo and add our composer.json file.
2. Adding Auto-loading and the Service Provider
In this video we'll show you how you can auto-load your package and we'll also show you how to create your package Service Provider.
To learn more about PSR-4 standards you can follow this link: http://www.php-fig.org/psr/psr-4/
To learn more about Service Providers you can checkout the Laravel Documentation Section on Service Providers to learn all about them.
3. Creating Routes for Your Package
In this video we'll be including a new route file in our service provider. This means that our package will have it's own routes. You will see how easy this is to implement as we echo out some text to the screen to gaurantee that our package routes are being created.
4. Creating a Package Controller
In this video we'll be creating our first package controller. We'll then be mapping our route to our controller and displaying some content to the screen. We'll also add an optional parameter to the end of the route and pass it to the controller.
5. Creating Views for our Package
In this video we'll be creating a view for our package. Instead of displaying data from our route closure or our controller it's always best to display it from a view. We'll show you how you can load views from a location inside of your package.
6. Creating a new Github repo for your Package
In this episode you will learn how to add your package to Github and tag it with a version. Tagging your package with a particular version is very important because this decides which version of your package your users will download when they include your package in their application.
7. Submitting your Package to Packagist
In this episode you'll learn how to submit your package to the Packagist website. When you submit your package to the Packagist website it will be ready for other users to include in their application.
8. Requiring your Package in a new Application
In this video we'll show you how you can require the new package that we have created in a new application. We'll also show you how you can tag a new version of your package.
9. Package Auto-discovery
Adding package auto-discovery for your package will allow composer and Laravel to automatically discover your Service Provider. This means that when users require your package they will no longer have to manually add the Service Provider to their config/app.php
You can learn more about Package Auto-Discovery from the following article: https://devdojo.com/blog/tutorials/package-auto-discovery
10. Working on the dev-master branch
Working on the dev-master branch will allow you to work on your package directly from your vendor folder to test out functionality. Certain times you may want to work with different branches in your package. In order to do that you can just add dev- to the beginning of the branch name when you require the package.
For example say that you had a branch with a name of feature1, you would then include this branch with composer by running the following command:
composer require devdojo/welcome dev-feature1
11. Publishable assets in your package
In this video we'll show you how to add some publishable assets to your package. We'll add a new stylesheet to give our view a little bit of style and we will publish that file to the public folder.
12. Overriding Views and Wrapping Up
In this video we'll show you how you can override your package views. This allows users of your package to create a new view that will override the view you have created in your package. This view overriding is very simple and is available out of the box with Laravel.
Hope you have enjoyed learning Package Development and I hope to see more awesome and creative packages.
Resources
Link to the Package on Github: https://github.com/thedevdojo/welcome
Link to the Package on the Packagist Website: https://packagist.org/packages/devdojo/welcome
Comments (0)