1. Go to this page and download the library: Download panchodp/laravel-actions 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/ */
// Usage
$action = new MyAction();
$action->handle($attributes);
// Generated code
public function handle(array $attributes): void
{
// Implementation
}
// Usage
MyAction::handle($attributes);
// Generated code
public static function handle(array $attributes): void
{
// Implementation
}
declare(strict_types=1);
namespace App\Actions\User;
use Throwable;
final class CreateAccount
{
public function handle(array $attributes): void
{
// This is where the action logic will be implemented.
}
}
final class MyAction
{
public static function handle(User $user, MyActionRequest $request): void
{
DB::transaction(function () use ($request) {
// Logic to be executed within the transaction
});
}
}