1. Go to this page and download the library: Download hivokas/laravel-handlers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hivokas / laravel-handlers example snippets
return [
/*
|--------------------------------------------------------------------------
| Base Handler Class
|--------------------------------------------------------------------------
|
| Here you may specify which class will be used as the base class
| for all generated handlers.
|
*/
'base' => Hivokas\LaravelHandlers\Handler::class,
];
namespace App\Http\Handlers\Foo;
use App\Models\Foo;
use App\Services\FooService;
use Hivokas\LaravelHandlers\Handler;
use App\Http\Requests\Foo\UpdateFooRequest;
class UpdateFoo extends Handler
{
protected $service;
public function __construct(FooService $service)
{
$this->service = $service;
}
public function __invoke(UpdateFooRequest $request, Foo $foo)
{
$this->bar($foo, $request->validated());
return redirect('foo.show', $foo);
}
protected function bar(Foo $foo, array $validated)
{
return $this->service->baz($foo, $validated);
}
}
// app/Providers/RouteServiceProvider.php
protected function mapHandlersRoutes()
{
Route::middleware('web')
->namespace('App\Http\Handlers')
->group(base_path('routes/handlers.php'));
}
// app/Providers/RouteServiceProvider.php
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapHandlersRoutes();
//
}