feat: enhance CreditsPlus and NavbarManager extensions with improved role checks, route handling, and migration logic for better functionality and compatibility across databases
This commit is contained in:
@@ -30,6 +30,61 @@ class NavbarLink extends Model
|
||||
'route_params' => 'json',
|
||||
];
|
||||
|
||||
/**
|
||||
* Set route_params attribute - convert repeater format to associative array
|
||||
*/
|
||||
public function setRouteParamsAttribute($value)
|
||||
{
|
||||
if (is_array($value) && !empty($value)) {
|
||||
// Check if it's in repeater format [['key' => 'foo', 'value' => 'bar']]
|
||||
$firstItem = reset($value);
|
||||
if (is_array($firstItem) && isset($firstItem['key']) && isset($firstItem['value'])) {
|
||||
// Convert to associative array
|
||||
$params = [];
|
||||
foreach ($value as $item) {
|
||||
if (isset($item['key']) && isset($item['value'])) {
|
||||
$params[$item['key']] = $item['value'];
|
||||
}
|
||||
}
|
||||
$this->attributes['route_params'] = json_encode($params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise store as-is
|
||||
$this->attributes['route_params'] = is_string($value) ? $value : json_encode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get route_params attribute - convert to repeater format for Filament
|
||||
*/
|
||||
public function getRouteParamsAttribute($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$decoded = is_string($value) ? json_decode($value, true) : $value;
|
||||
|
||||
if (!is_array($decoded)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If it's already in repeater format, return as-is
|
||||
$firstItem = reset($decoded);
|
||||
if (is_array($firstItem) && isset($firstItem['key']) && isset($firstItem['value'])) {
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
// Convert associative array to repeater format for Filament
|
||||
$repeaterFormat = [];
|
||||
foreach ($decoded as $key => $val) {
|
||||
$repeaterFormat[] = ['key' => $key, 'value' => $val];
|
||||
}
|
||||
|
||||
return $repeaterFormat;
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(NavbarLink::class, 'parent_id');
|
||||
|
||||
Reference in New Issue
Block a user