1. Go to this page and download the library: Download aesircloud/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/ */
namespace App\Actions;
use AesirCloud\LaravelActions\Action;
class CreateUser extends Action
{
public function handle()
{
// Your logic here...
}
}
$user = CreateUser::run($data);
$pending = CreateUser::dispatch($data);
// app/Actions/MyAction.php
namespace App\Actions;
use AesirCloud\LaravelActions\Action;
use Illuminate\Http\Request;
class MyAction extends Action
{
public function handle(): mixed
{
return 'Hello world!';
}
public function asController(Request $request): mixed
{
// e.g., $data = $request->validate([...]);
return $this->handle();
}
}
// routes/web.php
use App\Actions\MyAction;
use Illuminate\Support\Facades\Route;
Route::get('/my-action', MyAction::class);
namespace App\Actions;
use AesirCloud\LaravelActions\Action;
use Illuminate\Http\Request;
class MyAction extends Action
{
public function handle(): mixed
{
return 'Default logic (if you still want to call it externally).';
}
// Typical controller method:
public function index(Request $request): mixed
{
return 'Called via index method!';
}
public function store(Request $request): mixed
{
return 'Called via store!';
}
}