Creating packages in Laravel 5
Developers experienced a slight trouble when they removed workbench. Now you have to create your own package structures yourself. Let’s see how to create workbench manually and make everything needed for package development lined up.
First add illuminate/workbench package to your composer.json file as:
"illuminate/workbench": "dev-master"
Now add the WorkbenchServiceProvider into config/app.php
'Illuminate\Workbench\WorkbenchServiceProvider'
Since the workbench has been removed in Laravel 5 you have to create it by yourself.
<?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' => '',
/*
|--------------------------------------------------------------------------
| 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' => '',
];
After creating file fill the information in your config file so that you can use workbench command.
php artisan workbench vendor/name
Now its time to create your own package structure in the packages directory.
packages/
vendor/
awesome/
src/
Awesome.php
composer.json
Vendor-Your vendor name.
Awesome-package name.
src-The business logic should be put in this folder.
In the packages/vendor/awesome directory run the below command to generate composer.json file.
composer init
In the src directory create an Awesome.php class and add a simple method.
<?php namespace Vendor/Awesome;
class Awesome
{
public static function printAwesomeness()
{
echo 'Awesome';
}
}
In the psr-4 autoloader of laravel composer.json, add the package
"autoload": {
"psr-4": {
"App\\": "app/",
"Vendor\\Awesome\\": "packages/vendor/awesome/src"
}
},
Now run composer autoloader dump command.
composer dump-autoload
Comments
0 comments
Please Sign in or Create an account to Post Comments