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


namespace App\Actions;

use App\Models\Post;
use Laraditz\Action\Action;

class CreateNewPost extends Action
{
    public function __construct(
        public string $title,
        public string $body
    )
    {}

    public function handle(): void
    {
        // You can use $this->data() helper to retreive all properties.
        Post::create($this->data());
    }
}

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

$createNewPost->handle();

CreateNewPost::run(
    title: 'My first post',
    body: 'This is a post content'
);