Fix Pint formatting
This commit is contained in:
+47
-41
@@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class Role extends BaseModel
|
||||
{
|
||||
@@ -19,11 +18,12 @@ class Role extends BaseModel
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected $casts = [
|
||||
'priority' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
'priority' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
@@ -52,43 +52,47 @@ class Role extends BaseModel
|
||||
* Find roles by names or slugs (case-insensitive), active only, ordered by priority ASC.
|
||||
*/
|
||||
|
||||
// Put these INSIDE the Role model, replacing the current implementations
|
||||
// Put these INSIDE the Role model, replacing the current implementations
|
||||
|
||||
public static function findByNamesOrSlugs(array $keys): array
|
||||
{
|
||||
$keys = array_values(array_filter(array_map('strval', $keys)));
|
||||
if (empty($keys)) return [];
|
||||
public static function findByNamesOrSlugs(array $keys): array
|
||||
{
|
||||
$keys = array_values(array_filter(array_map('strval', $keys)));
|
||||
if (empty($keys)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$lower = array_map('mb_strtolower', $keys);
|
||||
$placeholders = implode(',', array_fill(0, count($lower), '?'));
|
||||
$lower = array_map('mb_strtolower', $keys);
|
||||
$placeholders = implode(',', array_fill(0, count($lower), '?'));
|
||||
|
||||
return static::query()
|
||||
->active()
|
||||
->where(function (Builder $q) use ($lower, $placeholders) {
|
||||
$q->whereRaw("LOWER(name) IN ($placeholders)", $lower)
|
||||
->orWhereRaw("LOWER(slug) IN ($placeholders)", $lower);
|
||||
})
|
||||
->orderBy('priority', 'asc')
|
||||
->get()
|
||||
->all();
|
||||
}
|
||||
return static::query()
|
||||
->active()
|
||||
->where(function (Builder $q) use ($lower, $placeholders) {
|
||||
$q->whereRaw("LOWER(name) IN ($placeholders)", $lower)
|
||||
->orWhereRaw("LOWER(slug) IN ($placeholders)", $lower);
|
||||
})
|
||||
->orderBy('priority', 'asc')
|
||||
->get()
|
||||
->all();
|
||||
}
|
||||
|
||||
public static function getIdsByNames(array $names): array
|
||||
{
|
||||
$names = array_values(array_filter(array_map('strval', $names)));
|
||||
if (empty($names)) return [];
|
||||
public static function getIdsByNames(array $names): array
|
||||
{
|
||||
$names = array_values(array_filter(array_map('strval', $names)));
|
||||
if (empty($names)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$lower = array_map('mb_strtolower', $names);
|
||||
$placeholders = implode(',', array_fill(0, count($lower), '?'));
|
||||
$lower = array_map('mb_strtolower', $names);
|
||||
$placeholders = implode(',', array_fill(0, count($lower), '?'));
|
||||
|
||||
$ids = static::query()
|
||||
->select('id')
|
||||
->whereRaw("LOWER(name) IN ($placeholders)", $lower)
|
||||
->pluck('id')
|
||||
->all();
|
||||
$ids = static::query()
|
||||
->select('id')
|
||||
->whereRaw("LOWER(name) IN ($placeholders)", $lower)
|
||||
->pluck('id')
|
||||
->all();
|
||||
|
||||
return array_map('intval', $ids);
|
||||
}
|
||||
return array_map('intval', $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dashboard_route by name or slug (case-insensitive), active only.
|
||||
@@ -96,7 +100,9 @@ public static function getIdsByNames(array $names): array
|
||||
public static function getRouteByNameOrSlug(string $key): ?string
|
||||
{
|
||||
$key = trim((string) $key);
|
||||
if ($key === '') return null;
|
||||
if ($key === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$lower = mb_strtolower($key);
|
||||
|
||||
@@ -104,7 +110,7 @@ public static function getIdsByNames(array $names): array
|
||||
->active()
|
||||
->where(function (Builder $q) use ($lower) {
|
||||
$q->whereRaw('LOWER(name) = ?', [$lower])
|
||||
->orWhereRaw('LOWER(slug) = ?', [$lower]);
|
||||
->orWhereRaw('LOWER(slug) = ?', [$lower]);
|
||||
})
|
||||
->first();
|
||||
|
||||
@@ -141,12 +147,12 @@ public static function getIdsByNames(array $names): array
|
||||
public static function rules(?int $id = null): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255', 'unique:roles,slug,' . ($id ?? 'NULL') . ',id'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255', 'unique:roles,slug,'.($id ?? 'NULL').',id'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'dashboard_route' => ['nullable', 'string', 'max:255'],
|
||||
'priority' => ['nullable', 'integer', 'min:0'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
'priority' => ['nullable', 'integer', 'min:0'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user