Skip to content

Commit

Permalink
third party packages page issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Jul 21, 2022
1 parent 45c2f9c commit 91cae8b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/FilamentShield.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function generateForResource(string $resource): void
collect(config('filament-shield.permission_prefixes.resource'))
->each(function ($prefix) use ($resource, $permissions) {
$permissions->push(Permission::firstOrCreate(
['name' => $prefix . '_' . Str::lower($resource)],
['name' => $prefix . '_' . $resource],
['guard_name' => config('filament.auth.guard')]
));
});
Expand Down Expand Up @@ -101,11 +101,16 @@ public static function getResources(): ?array
return true;
})
->reduce(function ($resources, $resource) {
$resource = Str::of($resource)->afterLast('\\')->before('Resource')->snake()->toString();
$resources[$resource] = $resource;
$name = Str::of($resource)->afterLast('Resources\\')->before('Resource')->replace('\\', '')->headline()->snake()->replace('_', '::')->toString();
$resources[$name] = [
'resource' => $name,
'fqcn' => $resource,
];

return $resources;
}, []);
}, collect())
->sortKeys()
->toArray();
}

/**
Expand All @@ -117,7 +122,7 @@ public static function getResources(): ?array
public static function getLocalizedResourceLabel(string $entity): string
{
$label = collect(Filament::getResources())->filter(function ($resource) use ($entity) {
return Str::of($resource)->endsWith(Str::of($entity)->headline()->replace(' ', '')->toString().'Resource');
return $resource === $entity;
})->first()::getModelLabel();

return Str::of($label)->headline();
Expand Down Expand Up @@ -152,7 +157,7 @@ public static function getPages(): ?array
return true;
})
->reduce(function ($pages, $page) {
$name = Str::of($page)->after('Pages\\')->replace('\\', '')->snake()->prepend(config('filament-shield.permission_prefixes.page').'_');
$name = Str::of($page)->afterLast('\\')->snake()->prepend(config('filament-shield.permission_prefixes.page').'_');
$pages["{$name}"] = "{$name}";

return $pages;
Expand Down Expand Up @@ -234,7 +239,6 @@ protected static function transformClassString(string $string, bool $isPageClass
->after('_')
->headline()
->replace(' ', '')
->toString()
));
}

Expand Down

0 comments on commit 91cae8b

Please sign in to comment.