PHP code example of kirschbaum-development / laravel-actions

1. Go to this page and download the library: Download kirschbaum-development/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/ */

    

kirschbaum-development / laravel-actions example snippets


 /**
  * Event to dispatch before action starts.
  *
  * @var string
  */
 public $before = ChuckNorrisWillBlowYourMind::class;

 /**
  * Event to dispatch after action completes.
  *
  * @var string
  */
 public $after = ChuckNorrisBlewYourMind::class;

/**
 * Create a new action instance.
 *
 * @return void
 */
public function __construct()
{
    // Pass any arguments you need.
}

/**
 * Execute the action.
 *
 * @return mixed
 */
public function __invoke()
{
    // Handle your action here.
}

ChuckNorris::act($data);
ChuckNorris::actWhen($isChuckNorrisMighty, $data);
ChuckNorris::actUnless($isChuckNorrisPuny, $data);

use Kirschbaum\Actions\Facades\Action;

Action::act(ChuckNorris::class, $data);
Action::actWhen($isChuckNorrisMighty, ChuckNorris::class, $data);
Action::actUnless($isChuckNorrisPuny, ChuckNorris::class, $data);

act(ChuckNorris::class, $data);
act_when($isChuckNorrisMighty, ChuckNorris::class, $data);
act_unless($isChuckNorrisPuny, ChuckNorris::class, $data);

use Kirschbaum\Actions\Action;

public function index (Action $action)
{
    $action->act(ChuckNorris::class, $data);
    $action->actWhen($isChuckNorrisMighty, ChuckNorris::class, $data);
    $action->actUnless($isChuckNorrisPuny, ChuckNorris::class, $data);
}

/**
 * Handle failure of the action.
 *
 * @throws Throwable
 *
 * @return mixed
 */
public function failed(Throwable $exception)
{
    event(new VanDammeFailedEvent);
}

/**
 * Event to dispatch if action throws an exception.
 *
 * @var string
 */
public $exception = SeagalFailedException::class;

return [
    'paths' => [],
];

use Kirschbaum\Actions\Facades\Action;

Action::shouldReceive('act')
    ->once()
    ->andReturnTrue();

use Kirschbaum\Actions\Action;

$this->mock(Action::class, function ($mock) {
    $mock->shouldReceive('act')
        ->once()
        ->andReturnTrue();
});

use App\Actions\ChuckNorris;

$this->mock(ChuckNorris::class, function ($mock) {
    $mock->shouldReceive('act')
        ->once()
        ->andReturnTrue();
});

new ChuckNorris($data);
bash
php artisan make:action ChuckNorris
bash
php artisan vendor:publish --tag laravel-actions