PHP code example of laravie / cabinet

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

    

laravie / cabinet example snippets




namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravie\Cabinet\Cabinet;

class User extends Authenticatable
{
    use Cabinet;
}



namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravie\Cabinet\Cabinet;

class User extends Authenticatable
{
    use Cabinet;

    /**
     * Configure cabinet for the eloquent model.
     * 
     * @param  \Laravie\Cabinet\Repository  $cabinet 
     * @return void
     */
    protected function onCabinet($cabinet)
    {
        $cabinet->setStorage(resolve('cache.store'));
    }
}

Laravie\Cabinet\Repository::share(string $key, callable $callback);

$user->cabinet()->share('birthday', static function ($user) {
    return now()->diffInDays($user->birthdate);
});

Laravie\Cabinet\Repository::share(string $key, callable $callback, $ttl = null);

$user->cabinet()->share('birthday', static function ($user) {
    return now()->diffInDays($user->birthdate);
}, 60);

Laravie\Cabinet\Repository::forever(string $key, callable $callback);

$user->cabinet()->share('birthday', static function ($user) {
    return now()->diffInDays($user->birthdate);
}, 'forever');

// or

$user->cabinet->forever('birthday', static function ($user) {
    return now()->diffInDays($user->birthdate);
})

Laravie\Cabinet\Repository::get(string $key);

$user->cabinet()->get('birthday');

// or

$user->cabinet('birthday');

Laravie\Cabinet\Repository::forget(string $key);

$user->cabinet()->forget('birthday');

Laravie\Cabinet\Repository::flush();

$user->cabinet()->flush();