56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
|
|
|
enum OrdersEnum: int
|
|
{
|
|
use BaseEnum;
|
|
|
|
case asc = 1;
|
|
case desc = 2;
|
|
|
|
/**
|
|
* Labels definition.
|
|
*
|
|
* @phpstan-ignore-next-line
|
|
*/
|
|
private const LABELS = [
|
|
self::asc->name => 'enums.orders.asc',
|
|
self::desc->name => 'enums.orders.desc',
|
|
];
|
|
|
|
/**
|
|
* Get the orders to display using the app locale.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function ordersWithLocal(): bool
|
|
{
|
|
$locale = config('app.locale');
|
|
return match ($this) {
|
|
self::asc,
|
|
/** @phpstan-ignore-next-line */
|
|
self::desc => true,
|
|
default => $locale === "fr" ? true : false,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Optional factory from label.
|
|
*
|
|
* @param string $name
|
|
* @return self
|
|
*/
|
|
public static function makeFromLabel(string $name): ?self
|
|
{
|
|
foreach (self::cases() as $case) {
|
|
if ($case->name() === $name) {
|
|
return $case;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|