PHP code example of frictionlessdigital / actions

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

    

frictionlessdigital / actions example snippets


return $this->tap(User::first(), fn(User $user) => $user->delete());


$user = User::first();

$user->delete();

return $user;

// $user;

return $this->pipe(User::first(), fn($user) => $user->delete());

$user = User::first();

return $user->delete();

// true;

use Fls\Actions\Action;

class UserAction extends Action
{
    public function rules()
    {
        return [
            'name' => ['ction handle($attributes) {
        return $this->fill($attributes)->validated();
    }
}

UserAction::run([
    'name' => 'John',
    'email' => '[email protected]',
]);

//  ['name' => 'John', 'email' => '[email protected]']


use Fls\Actions\Action;

class UserAction extends Action
{
    ...
    public function handle(User $user, $attributes) {
        return $this->fill($attributes)
                    ->validate()
                    ->tap($user, fn(User $user) => $user->update($this->validated()));
    }
}


use Fls\Actions\Action;
use App\User;

class CreateUserAction extends Action
{
    public function handle(User $user, $attributes) 
    {
        return $user->create($attributes);
    }
}