PHP code example of sfolador / laravel-eloquent-toggle

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

    

sfolador / laravel-eloquent-toggle example snippets


use Illuminate\Database\Eloquent\Model;
use Sfolador\LaravelEloquentToggle\Casts\Boolean;

class User extends Model
{
    protected $casts = [
        'active' => Boolean::class,
    ];
    ...
}

$user = new User();
$user->active = true;

$user->active->toggle(); // false

$isActive = $user->active->value(); // false