1. Go to this page and download the library: Download kminek/laravel-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/ */
kminek / laravel-enum example snippets
use \MyCLabs\Enum\Enum;
class Brand extends Enum
{
public const TOYOTA = 'toyota';
public const BMW = 'bmw';
public const PEUGEOT = 'peugeot';
}
use \Kminek\LaravelEnum\Enum;
class Brand extends Enum
{
public const TOYOTA = 'toyota';
public const BMW = 'bmw';
public const PEUGEOT = 'peugeot';
}
class Car extends \Illuminate\Database\Eloquent\Model
{
protected $casts = [
'brand' => Brand::class,
];
}
class Car extends \Illuminate\Database\Eloquent\Model
{
protected $casts = [
'brand' => Brand::class.':nullable',
];
}
// set
$car = new Car();
$car->brand = new Brand(Brand::BMW);
// or
$car->brand = Brand::BMW;
// get
$brand = $car->brand; // $brand is enum instance
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.