PHP code example of dcodegroup / laravel-state-machines
1. Go to this page and download the library: Download dcodegroup/laravel-state-machines 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/ */
dcodegroup / laravel-state-machines example snippets
use App\StateMachines\Users\AcceptedState;
use App\StateMachines\Users\PendingState;
use App\StateMachines\Users\RejectedState;
use http\Exception\InvalidArgumentException;
public function state()
{
return match($this->status->machine_name) {
'accepted' => new AcceptedState($this),
'pending' => new PendingState($this),
'rejected' => new RejectedState($this),
'default' => throw new InvalidArgumentException('Invalid state'),
}
}
$user->state()->approve();
php artisan vendor:publish --tag=statuses-migrations