Files
new_raffles/app/Traits/StatusTrait.php
2025-07-27 17:40:56 +05:45

32 lines
855 B
PHP

<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Casts\Attribute;
trait StatusTrait
{
const STATUS = [
11 => 'Active',
10 => 'In-Active',
];
protected function statusName(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
switch ($attributes['status']) {
case '10':
return '<span class="badge bg-danger">' . self::STATUS[$attributes['status']] . '</span>';
case '11':
return '<span class="badge bg-success">' . self::STATUS[$attributes['status']] . '</span>';
default:
# code...
break;
}
},
set: fn($value) => $value,
);
}
}