PHP code example of arandu / laravel-safe-json-cast

1. Go to this page and download the library: Download arandu/laravel-safe-json-cast 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/ */

    

arandu / laravel-safe-json-cast example snippets


use Arandu\LaravelSafeJsonCast\Json;

class User extends Model
{
    protected $casts = [
        'options' => Json::class,
    ];
}

$user = User::create([
    'name' => 'John Doe',
    'options' => [
        'foo' => 'bar',
    ],
]);

$user->options->foo; // bar