/setup-laravel5-package

Steps to create Laravel 5 package

Primary LanguagePHP

Laravel 5 package Development from scratch

Trying to explain laravel 5 package development 👍

how to create laravel specific packages. With 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.

  • Step 1 : Install Laravel

http://laravel.com/docs/5.0#install-laravel

Note :In my above root i haven't added 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.

  • Step 2 : Create package folder and service provider

In root directory create a folder call "packages" /"vendorName"/"packageName"/src" Eg: root/packages/jai/Contact/src

now navigate to src folder and create a service provider class: "ContactServiceprovider.php"

your service provider should extend ServiceProvider which has to implement register method.

Please look into this file

If you want you can have dd("testing"); in boot function and go to step 3 but you have copied the file you might want to create views , routes , config and controllers

-Creating : Routes create a "Http" folder in your "Http" folder create routes.php like this file

  • creating : controller

in your Http folder create a new directory called " Controllers" and then in this folder create ContactController.php like this file

  • creating Config : in your /packages/jai/Contact/src/config and in it create file call 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/conifg/contact.php) and then you can access config.

  • Creating Views :

this is a bit different , in your jai/Contact folder create a new folder call views and you can replicate these files. file1 file2

  • Step 3 : add package path in root composer.json

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/",
  		}
  • step 4 : add service provider in app conifg.

    in your root/conifg/app.php under providers add your package service provider to hook your package in.

      		'Jai\Contact\ContactServiceProvider',
    
  • Step 5 : run composer dump-autoload - make sure there are no errors.

all done - now you can access your package via url - "yourwebsite/contact" DO share it you like it .

Official Documentation

Documentation for the framework can be found on the Laravel website.

Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the Laravel documentation.

License

The Laravel framework is open-sourced software licensed under the MIT license