Using handler class instead of controller class in Laravel 5.5+
- php >=7.1.3
- Laravel 5.5+
Laravel 6.0+ requires php 7.2+
Begin by pulling in the package through Composer.
$ composer require oanhnn/laravel-handlers
After that, publish vendor's resources:
$ php artisan vendor:publish --tag=laravel-handlers-config
After that, copy the config file from the vendor directory:
$ cp vendor/oanhnn/laravel-handlers/config/handlers.php config/handlers.php
Update base handler class to your class in config/handlers.php
.
Register the config file and the service provider in bootstrap/app.php
:
$app->configure('handlers');
$app->register(Laravel\Handlers\ServiceProvider::class);
Create new handler class by run command
$ php artisan make:handler ShowProfile
You can use --force
option to force create handler class (override existed class)
$ php artisan make:handler --force ShowProfile
You can change namespace of handler classes by config namespace
in config/handlers.php
file.
'namespace' => '\\App\\Http\\Api',
You can change base handler class by config base
in config/handlers.php
file.
'base' => '\App\Http\Controllers\Controller::class',
If you want customize stub file, please run:
$ php artisan vendor:publish --tag=laravel-handlers-stubs
See all change logs in CHANGELOG
$ git clone git@github.com/oanhnn/laravel-handlers.git /path
$ cd /path
$ composer install
$ composer phpunit
Please see CONTRIBUTING for details.
If you discover any security related issues, please email to Oanh Nguyen instead of using the issue tracker.
This project is released under the MIT License.
Copyright © Oanh Nguyen.