PHP code example of codewiser / laravel-enum-casting

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

    

codewiser / laravel-enum-casting example snippets


use \Codewiser\Enum\Castable\AsArray;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'roles' => AsArray::class . ':set,' . MyEnum::class,
];

use \Codewiser\Enum\Castable\AsArrayObject;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'roles' => AsArrayObject::class . ':json,' . MyEnum::class,
];

use \Codewiser\Enum\Castable\AsCollection;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'roles' => AsCollection::class . ':array,' . MyEnum::class . ',' . MyCollection::class,
];