PHP code example of panchodp / laravel-actions

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/ */

    

panchodp / laravel-actions example snippets


return [
    'base_folder' => 'Actions',
    'method_name' => 'handle',
];

// 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
        });
    }
}
bash
php artisan vendor:publish --provider="Panchodp\LaravelAction\LaravelActionServiceProvider" --tag="laravel-actions-config"
bash
php artisan vendor:publish --provider="Panchodp\LaravelAction\LaravelActionServiceProvider" --tag="laravel-actions-stubs"
bash
php artisan make:action
bash
php artisan make:action MyAction
bash
php artisan make:action User/CreateAccount
bash
php artisan make:action User/Auth/Login
bash
php artisan make:action Admin\DeletePost
bash
php artisan make:action MyAction -tur    # transaction + user + request
php artisan make:action MyAction -turs   # + static method

# Long form works too
php artisan make:action MyAction --transaction --user --request
bash
php artisan actions:list