@@ 8-52 (lines=45) @@ | ||
5 | use Illuminate\Console\Command; |
|
6 | use Spatie\Permission\Models\Permission; |
|
7 | ||
8 | class AddPermission extends Command |
|
9 | { |
|
10 | /** |
|
11 | * The name and signature of the console command. |
|
12 | * |
|
13 | * @var string |
|
14 | */ |
|
15 | protected $signature = 'permission:create-permission {name : The name of the permission} {guard? : Optional guard, default web}'; |
|
16 | ||
17 | /** |
|
18 | * The console command description. |
|
19 | * |
|
20 | * @var string |
|
21 | */ |
|
22 | protected $description = 'Create a permission'; |
|
23 | ||
24 | /** |
|
25 | * Create a new command instance. |
|
26 | * |
|
27 | * @return void |
|
28 | */ |
|
29 | public function __construct() |
|
30 | { |
|
31 | parent::__construct(); |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * Execute the console command. |
|
36 | * |
|
37 | * @return mixed |
|
38 | */ |
|
39 | public function handle() |
|
40 | { |
|
41 | $permission_data = ['name' => $this->argument('name')]; |
|
42 | ||
43 | $guard = $this->argument('guard'); |
|
44 | if ($guard) { |
|
45 | $permission_data['guard_name'] = $guard; |
|
46 | } |
|
47 | ||
48 | $permission = Permission::create($permission_data); |
|
49 | $this->info('Permission `'.$permission->name.'` created at ID: '.$permission->id); |
|
50 | } |
|
51 | } |
|
52 |
@@ 8-52 (lines=45) @@ | ||
5 | use Illuminate\Console\Command; |
|
6 | use Spatie\Permission\Models\Role; |
|
7 | ||
8 | class AddRole extends Command |
|
9 | { |
|
10 | /** |
|
11 | * The name and signature of the console command. |
|
12 | * |
|
13 | * @var string |
|
14 | */ |
|
15 | protected $signature = 'permission:create-role {name : The name of the role} {guard? : Optional guard, default web}'; |
|
16 | ||
17 | /** |
|
18 | * The console command description. |
|
19 | * |
|
20 | * @var string |
|
21 | */ |
|
22 | protected $description = 'Create a role'; |
|
23 | ||
24 | /** |
|
25 | * Create a new command instance. |
|
26 | * |
|
27 | * @return void |
|
28 | */ |
|
29 | public function __construct() |
|
30 | { |
|
31 | parent::__construct(); |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * Execute the console command. |
|
36 | * |
|
37 | * @return mixed |
|
38 | */ |
|
39 | public function handle() |
|
40 | { |
|
41 | $role_data = ['name' => $this->argument('name')]; |
|
42 | ||
43 | $guard = $this->argument('guard'); |
|
44 | if ($guard) { |
|
45 | $role_data['guard_name'] = $guard; |
|
46 | } |
|
47 | ||
48 | $role = Role::create($role_data); |
|
49 | $this->info('Role `'.$role->name.'` created at ID: '.$role->id); |
|
50 | } |
|
51 | } |
|
52 |