StocksNew/app/Traits/StatusTrait.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

35 lines
961 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) {
// dd($value, $attributes);
switch ($attributes['status']) {
case '10':
return '<span class="badge bg-danger">' . self::STATUS[$attributes['status']] . '</span>';
break;
case '11':
return '<span class="badge bg-success">' . self::STATUS[$attributes['status']] . '</span>';
break;
default:
# code...
break;
}
},
set: fn($value) => $value,
);
}
}