Skip to content

👍 Using handler class instead of controller class in Laravel 5.5+

License

Notifications You must be signed in to change notification settings

oanhnn/laravel-handlers

Repository files navigation

Laravel Handlers

Latest Version Software License Build Status Coverage Status Total Downloads Requires PHP

Using handler class instead of controller class in Laravel 5.5+

Requirements

  • php >=7.1.3
  • Laravel 5.5+

Laravel 6.0+ requires php 7.2+

Installation

Begin by pulling in the package through Composer.

$ composer require oanhnn/laravel-handlers

Laravel

After that, publish vendor's resources:

$ php artisan vendor:publish --tag=laravel-handlers-config

Lumen

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);

Usage

Create handler 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

Configure

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',

Customize handler stub

If you want customize stub file, please run:

$ php artisan vendor:publish --tag=laravel-handlers-stubs

Changelog

See all change logs in CHANGELOG

Testing

$ git clone git@github.com/oanhnn/laravel-handlers.git /path
$ cd /path
$ composer install
$ composer phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email to Oanh Nguyen instead of using the issue tracker.

Credits

License

This project is released under the MIT License.
Copyright © Oanh Nguyen.