adding counter on menu
This commit is contained in:
@@ -21,6 +21,7 @@ class Menu extends Model
|
||||
'name',
|
||||
'icon',
|
||||
'route_or_url',
|
||||
'counter_handler',
|
||||
'position',
|
||||
'enable',
|
||||
'actives',
|
||||
@@ -34,6 +35,13 @@ class Menu extends Model
|
||||
'permissions',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = [
|
||||
'counter',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
@@ -88,4 +96,14 @@ class Menu extends Model
|
||||
set: fn ($value) => is_array($value) || $value instanceof JsonSerializable || $value instanceof stdClass ? json_encode($value) : $value,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
*/
|
||||
public function counter() : Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->counter_handler ? new $this->counter_handler : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user