1. Go to this page and download the library: Download iteks/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/ */
iteks / laravel-enum example snippets
use Iteks\Attributes\Description;
use Iteks\Traits\BackedEnum;
use Iteks\Traits\HasAttributes;
enum BackedEnumShape: string
{
use BackedEnum;
use HasAttributes;
#[Description('A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center')]
case RoundCircle = 'circle';
}
enum BackedEnumShape: string
{
#[Description('A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center')]
case RoundCircle = 'circle';
}
enum BackedEnumShape: string
{
#[Id(1)]
case RoundCircle = 'circle';
}
// Result:
[
'simpleValue' => 'circle',
'description' => 'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'id' => 1,
'label' => 'Round Circle',
'metadata' => [
'color' => 'red',
'sides' => 0,
'type' => 'curved'
]
]
// Result:
[
'RoundCircle' => [
'description' => 'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'label' => 'Round Circle'
],
'BoxSquare' => [
'description' => 'A square is a regular quadrilateral',
'label' => 'Perfect Square'
],
'RightTriangle' => [
'description' => 'A triangle is a polygon with three edges and three vertices',
'label' => 'Right-Triangle'
],
...
]
// Result:
[
'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'A square is a regular quadrilateral',
'A triangle is a polygon with three edges and three vertices',
'A star is a self-intersecting, equilateral polygon',
'A rectangle is a quadrilateral with four right angles'
]
// Result:
[
'RoundCircle' => 'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'BoxSquare' => 'A square is a regular quadrilateral',
...
]
// Result:
[
'simpleValue' => 'circle',
'description' => 'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'id' => 1,
'label' => 'Round Circle',
'metadata' => [
'color' => 'red',
'sides' => 0,
'type' => 'curved'
]
]
// Result:
[
'RoundCircle' => [
'description' => 'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'label' => 'Round Circle'
],
'BoxSquare' => [
'description' => 'A square is a regular quadrilateral',
'label' => 'Perfect Square'
],
'RightTriangle' => [
'description' => 'A triangle is a polygon with three edges and three vertices',
'label' => 'Right-Triangle'
],
...
]
// Result:
'A square is a regular quadrilateral, all sides have equal length and all angles are 90 degrees'
$descriptions = BackedEnumShape::descriptions();
// Result:
[
'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'A square is a regular quadrilateral, all sides have equal length and all angles are 90 degrees',
'A triangle is a polygon with three edges and three vertices',
'A star is a self-intersecting, equilateral polygon',
'A rectangle is a quadrilateral with four right angles'
]
$descriptions = BackedEnumShape::descriptions('name');
// Result:
[
'RoundCircle' => 'A circle is a perfectly round geometric figure, every point on the circle is equidistant from the center',
'BoxSquare' => 'A square is a regular quadrilateral',
...
]