|
@@ -7,6 +7,7 @@ use App\Models\PermissionGroup;
|
|
|
use App\Models\Role;
|
|
|
use Illuminate\Console\Command;
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
+use Illuminate\Support\Str;
|
|
|
|
|
|
class InitializeRoutePermission extends Command
|
|
|
{
|
|
@@ -31,10 +32,6 @@ class InitializeRoutePermission extends Command
|
|
|
{
|
|
|
$routes = Route::getRoutes();
|
|
|
|
|
|
- $permissionGroup = PermissionGroup::query()->firstOrCreate([
|
|
|
- 'name' => 'default',
|
|
|
- ]);
|
|
|
-
|
|
|
foreach ($routes as $route) {
|
|
|
if (! $route->getName()) {
|
|
|
continue;
|
|
@@ -43,6 +40,14 @@ class InitializeRoutePermission extends Command
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ $routeName = $route->getName();
|
|
|
+ $groupName = explode('.', $routeName)[0] ?? 'default';
|
|
|
+ $groupName = Str::of($groupName)->replace('-', ' ')->studly()->value();
|
|
|
+ $groupMap[$groupName] = PermissionGroup::query()->firstOrCreate([
|
|
|
+ 'name' => $groupName
|
|
|
+ ]);
|
|
|
+ $permissionGroup = $groupMap[$groupName];
|
|
|
+
|
|
|
Permission::query()->firstOrCreate([
|
|
|
'name' => $route->getName(),
|
|
|
'guard_name' => 'api',
|