first commit
This commit is contained in:
34
app/Traits/StatusTrait.php
Normal file
34
app/Traits/StatusTrait.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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,
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user