Trying to explain Laravel specific package development in Laravel 5 👍
With the new Laravel 5 - php artisan workbench
is made redundant.
And technically Laravel packages should not be tightly coupled with Laravel core, so that make sense.
But for some who wants to build Laravel specific packages I suppose this will help them to have a quick start.
http://laravel.com/docs/5.0#install-laravel
Note : In my above root i haven't added a .env file. You need to configure this.
Note : Laravel may require some permissions to be configured: folders within storage and vendor require write access by the web server.
In root directory create a folder called packages/vendorName/packageName/src
e.g. root/packages/jai/Contact/src
Now navigate to the src
folder and create a file for your service provider, e.g. ContactServiceprovider.php
.
Your service provider should extend ServiceProvider and has to implement the register
method.
Please look into this file for an example.
If you want you can write dd("testing");
in the boot function and go to step 3, but if you have copied the service provider file you might want to create views, routes, config and controllers.
In your src
folder create a new Http
folder in which you create your routes.php
file.
(example file)
In your Http
folder create a new directory called Controllers
. In this folder you can create your controllers.
(example file)
In your src
folder create a new directory and call it config
. In it create a new file (e.g. contact.php
) like this file
Note: if you want to access config - you need to publish first - after doing step 5 you can run php artisan vendor:publish
. This will push you config file (contact.php => project/config/contact.php) and then you can access config.
This is a bit different, in your package folder (e.g. jai/Contact
) create a new folder call views
.
(example file 1 example file 2)
In your root composer.json file "jai\\Contact\\": "packages/jai/Contact/src/"
under psr-4
"psr-4": {
"App\\": "app/",
"Jai\\Contact\\": "packages/jai/contact/src/",
}
In your root/config/app.php
under providers
add your package service provider to hook your package in.
'Jai\Contact\ContactServiceProvider',
run composer dump-autoload
- make sure there are no errors.
all done - now you can access your package via url - "yourwebsite/contact"
Check out Included test Branch for how we can Write test in Laravel Package.
DO share this repository if you liked it.
UPDATE :
New Branch added : Where Basic Tests are Included.