1. Go to this page and download the library: Download spatie/laravel-model-states 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/ */
spatie / laravel-model-states example snippets
use Spatie\ModelStates\HasStates;
class Payment extends Model
{
use HasStates;
protected $casts = [
'state' => PaymentState::class,
];
}
use Spatie\ModelStates\State;
use Spatie\ModelStates\StateConfig;
abstract class PaymentState extends State
{
abstract public function color(): string;
public static function config(): StateConfig
{
return parent::config()
->default(Pending::class)
->allowTransition(Pending::class, Paid::class)
->allowTransition(Pending::class, Failed::class)
;
}
}
class Paid extends PaymentState
{
public function color(): string
{
return 'green';
}
}