I am having trouble to create package in Laravel 5 as workbench
has been removed.
As in this thread (How create package in Laravel 5?), Goldorak suggest that we have to create our own package structure ourselves.
So, how can I create the workbench manually and get everything ready for package development?
You could use package on this named packman.
composer global require "hadefication/packman"
, just a simple package creator for Laravel.Using the laravel Workbench package:
You can add the
illuminate/workbench
package in a Laravel 5 by adding to yourcomposer.json
:then add the WorkbenchServiceProvider into your
config/app.php
file:Now you need to create the
config/workbench.php
file since it has been removed from Laravel 5:Fill your information in this config file then you will be able to use the workbench command:
Creating your own package structure
In this exemple we will create our package called awesome in a packages directory.
Here is the package structure:
To generate a composer.json file you can use this command in the
packages/vendor/awesome
directory:Now we create a
Awesome.php
class in thesrc
directory with a simple method:After that we add the package to the laravel
composer.json
psr-4 autoloader:and we dump the composer autoloader
Now you can use your package everywhere in your laravel 5 project. If you need some laravel specific feature like service provider or view publishing, use them as described in the Laravel 5.0 documentation.
laravel 5 Standards with out workbench.
Set 1 : install laravel as usual.
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.
Note: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 check link below for that
Step 3 : add package path in root
composer.json
in your root composer.json file"jai\Contact\": "packages/jai/Contact/src/"
under psr-4Step 4 : add service provider in app config.
in your root/conifg/app.php under providers add your package service provider to hook your package in.
Step 5 : run composer dump-autoload - make sure there are no errors.
all done - now you can access your package via url -
"yourwebsite/contact"
Resource from here : https://github.com/jaiwalker/setup-laravel5-package