1. Go to this page and download the library: Download mindtwo/native-enum 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/ */
namespace App\Models;
use App\Enums\UserRole;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $casts = [
'role' => UserRole::class,
];
}
namespace App\Enums;
use Illuminate\Contracts\Database\Eloquent\Castable;
enum UserRole: int implements Castable
{
use BaseEnum;
case ADMIN = 10;
case CUSTOMER = 50;
}
namespace App\Enums;
use Illuminate\Contracts\Database\Eloquent\Castable;
enum UserRole: int implements Castable
{
use BaseEnum;
case ADMIN = 10;
case CUSTOMER = 50;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.