PHP code example of laraditz / action

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

    

laraditz / action example snippets


'providers' => [
    ...
    Laraditz\Action\ActionServiceProvider::class,
    ...
],

...
$app->register(Laraditz\Action\ActionServiceProvider::class);
...

namespace App\Actions;

use Laraditz\Action\Action;

class CreateNewPost extends Action
{
    // Optional
    public function rules()
    {
        return [
            'title' => '  // use $this->validated() to get all validated attributes based on rules.
        // You also can use $this->all() to retreive all attributes passed if there is no rules.
    }
}

...
public function handle(Request $request)
{
    // Your logic goes here        
}
...

$createNewPost = new CreateNewPost([
    'title' => 'My first post', 
    'body' => 'This is a post content'
]);

$createNewPost->dispatch();

CreateNewPost::dispatch([
    'title' => 'My first post', 
    'body' => 'This is a post content'
]);

// routes/web.php
Route::post('posts', '\App\Actions\CreateNewPost');