PHP code example of uteq / laravel-model-actions

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

    

uteq / laravel-model-actions example snippets


use Uteq\ModelActions\Concerns\WithActions;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use WithActions;
}

$user->action()->update($input);
$user->action('update', $input);
$user->action(\App\Actions\User\Update::class, $input);

User::do(Create::class, $input);

return [
    /**
     * You can overwrite the method used to handle the
     * action. By default this is __invoke.
     */
    'method' => '__invoke',    
];

use Uteq\ModelActions\Concerns\WithActions;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use WithActions;
}

class Update
{
    public function __invoke(User $model, array $input = [])
    {
        // Now add you own logic here
    }
}

$user->action(Update::class, $input);

class Destroy
{
    public function __construct(
        protected PublicDestroyer $destroyer,
    ) { }
    
    public __invoke(User $user, array $input = [])
    {
        ($this->destroyer)($user, $input);
    }
}

class Action
{
    public function __invoke($var1, $var2)
    {
    
    }
}

User::do(Action::class, 'var1', 'var2');

class Action
{
    public function __invoke($name)
    {
    
    }
}

User::do(Action::class, name: 'test');

namespace App\Support;

use Uteq\ModelActions\Concerns\WithActions;

class Model extends \Illuminate\Database\Eloquent\Model
{
    use WithActions;
}

class ActionModel extends \App\Support\Model
{

} 
bash
php artisan vendor:publish --provider="Uteq\ModelActions\ModelActionsServiceProvider" --tag="laravel-model-actions-config"

App
├── Actions
│   └── User
│       ├── Create.php 
│       ├── Update.php 
│       ├── Destroy.php
│       └── AddImage.php
└── Models
    └── User.php