PHP code example of gurgentil / laravel-storable

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

    

gurgentil / laravel-storable example snippets




namespace App\Storables;

use App\Models\User;
use Gurgentil\LaravelStorable\Storable;

class StorableUser extends Storable
{
    /**
     * @var User
     */
    protected $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Get file path in storage.
     *
     * @return string
     */
    public function getFilePath(): string
    {
        return "users/{$this->user->uuid}.json";
    }

    /**
     * Get string representation of object to store.
     *
     * @return string
     */
    public function getContents(): string
    {
        return json_encode([
            'id' => $this->user->id,
            'email' => $this->user->email,
            'permissions' => $this->user->permissions->pluck('name')->toArray(),
        ]);
    }
}

$storable = new StorableUser($user);
$storable->save();

$storable = new StorableUser($user);
$storable->delete();

$storable = new StorableUser($user);
$storable->save('gcs');
bash
php artisan make:storable StorableUser