|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\Permission\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Spatie\Permission\Guard; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Spatie\Permission\Traits\AdaptiveCommandParams; |
|
10
|
|
|
use Spatie\Permission\Contracts\Permission as PermissionContract; |
|
11
|
|
|
|
|
12
|
|
|
class CreatePermission extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
use AdaptiveCommandParams; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The name of command. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $name = 'permission:create-permission'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The command description. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description = 'Create a permission'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The permission app. |
|
32
|
|
|
* |
|
33
|
|
|
* @var object |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $permissionApp; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The command constructor. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->permissionApp = app(PermissionContract::class); |
|
43
|
|
|
|
|
44
|
|
|
$this->registerCustomColumns($this->permissionApp); |
|
45
|
|
|
|
|
46
|
|
|
parent::__construct(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Execute the command. |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
public function handle() |
|
55
|
|
|
{ |
|
56
|
|
|
$permission = $this->permissionApp::findOrCreate($this->getInputParams()); |
|
57
|
|
|
|
|
58
|
|
|
$this->info("Permission `{$permission->name}` created"); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the command arguments. |
|
63
|
|
|
* |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getArguments() |
|
67
|
|
|
{ |
|
68
|
|
|
return array_merge([ |
|
69
|
|
|
['name', InputArgument::REQUIRED, 'The name of the permission'], |
|
70
|
|
|
], $this->requiredExtraFields); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get the command options. |
|
75
|
|
|
* |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function getOptions() |
|
79
|
|
|
{ |
|
80
|
|
|
return array_merge([ |
|
81
|
|
|
['guard', null, InputOption::VALUE_OPTIONAL, 'The name of the guard', Guard::getDefaultName($this->permissionApp)], |
|
82
|
|
|
], $this->optionalExtraFields); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|