Workbench Package Development for Laravel 5

workbench package development for laravel 5.x is depreciated , so before starting with this approach make sure you’re aware of it. Its just a matter for Laravel 5.0 version only later version support packager CLI command for creating packages. So if you’re planning to develop applications using Laravel 5.0 and needs to create packages rapidly then only try this option, Other  wise you can check my previous post regarding package creation of laravel 5.x.

Also if you’re planning to develop on Laravel 5.1 or later simply use this packages for creating your own packages.

Still you want workbench package development for laravel 5 just follow the instructions here, I select this method only due to few reason first of all php requirement for Laravel 5.0 is 5.4 or greater, most of the shared host available now are in PHP 5.4.x (August 2015).

Ok  lets start workbench pattern,

First you have to add the workbench support in your [label style=”3″] composer.json [/label] of root folder like below.

[code style=”1″]

“illuminate/workbench”: “dev-master”

[/code]

Now you can add the service provider in [label style=”3″] config\app.php [/label] file like below.

[code style=”1″]

‘Illuminate\Workbench\WorkbenchServiceProvider’

[/code]

Next step is to create a workbench configuration files in your config folder like  [label style=”3″]config\workbench.php [/label] and add the following content.

[code style=”1″]

<?php

return [
/*
|————————————————————————–
| Workbench Author Name
|————————————————————————–
|
| When you create new packages via the Artisan “workbench” command your
| name is needed to generate the composer.json file for your package.
| You may specify it now so it is used for all of your workbenches.
|
*/
‘name’ => ‘jobin jose’,
/*
|————————————————————————–
| Workbench Author E-Mail Address
|————————————————————————–
|
| Like the option above, your e-mail address is used when generating new
| workbench packages. The e-mail is placed in your composer.json file
| automatically after the package is created by the workbench tool.
|
*/
’email’ => ‘[email protected]’,
];

[/code]

Then just make sure you run the composer dumpautoload (some times its required composer dumpautoload – o).

Now you can simply creates packages using old laravel workbech CLI like.

[code style=”1″]

php artisan workbench VendorName/PackageName

[/code]

Ok now just check how it compatible for Laravel 5.x pattern, we know in Laravel 4.2 doesn’t have resource folder for overriding our packages view that has been done with [label style=”3″] app\view\[/label] folder so here its different even if you created the Packages using workbench you can make it Laravel 5.x way with following two lines in your serviceprovider of packages. add the following lines in your service provider boot method.

[code style=”1″]

$this->publishes([
__DIR__.’/views’ => base_path(‘resources/views/vendor/packagename’),
]);

[/code]

Then add your namespace in Laravel root’s composer.json like below.

[code style=”1″]

"psr-4": {
"App\\": "app/",
"Walkswithme\\Users\\": "workbench/walkswithme/users/src"
}
},

[/code]

Make sure you run the composer dumpautoload for loading your namespaces.

[code style=”1″] composer dumpautoload

[/code]

So you can run the vendor publish command for creating override for your packages.

[code style=”1″]

php artisan vendor:publish

[/code]

[info]This approach is experimental for quick development , not a good practise , to compromise Laravel 5.0 with PHP 5.4.x other wise always choose Laravel 5.1 if you have PHP 5.5.9 support on your hosting provider[/info]

 

Now you able to create a package using workbench pattern in Laravel 5.

Hope this article will help you to develop packages quickly. 🙂 🙂 🙂

 

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *