1. Go to this page and download the library: Download mahmudul/lara-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/ */
mahmudul / lara-enum example snippets
namespace App\Enums;
use Mahmudul\LaraEnum\Attributes\Description;
use Mahmudul\LaraEnum\Traits\HasEnumAttributes;
enum Status: string
{
use HasEnumAttributes;
#[Description('Draft')]
case DRAFT = 'draft';
#[Description('Published')]
case PUBLISHED = 'published';
// If no Description is provided, label() falls back to a humanized case name
case IN_REVIEW = 'in_review';
}
namespace App\Enums;
use Mahmudul\LaraEnum\Attributes\Translatable;
use Mahmudul\LaraEnum\Traits\HasEnumAttributes;
enum PaymentStatus: string
{
use HasEnumAttributes;
#[Translatable('enums.payment_status.pending')]
case PENDING = 'pending';
#[Translatable('enums.payment_status.paid')]
case PAID = 'paid';
}
// resources/lang/en/enums.php
return [
'payment_status' => [
'pending' => 'Pending',
'paid' => 'Paid',
],
];
// Usage (will call Laravel's __() helper under the hood):
PaymentStatus::PAID->label(); // "Paid"
Status::DRAFT->label(); // "Draft"
Status::IN_REVIEW->label(); // "In Review"