1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Console\Commands; |
17
|
|
|
|
18
|
|
|
use Illuminate\Support\Str; |
19
|
|
|
use Illuminate\Console\Command; |
20
|
|
|
use Illuminate\Support\Facades\Lang; |
21
|
|
|
use Illuminate\Contracts\Validation\Factory; |
22
|
|
|
|
23
|
|
|
class AbilityCreateCommand extends Command |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The name and signature of the console command. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $signature = 'fort:ability:create |
31
|
|
|
{name? : The name of the ability} |
32
|
|
|
{slug? : The slug of the ability} |
33
|
|
|
{--D|description= : The description of the ability}'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The console command description. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $description = 'Create a new ability.'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Execute the console command. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function handle() |
48
|
|
|
{ |
49
|
|
|
$data = array_filter([ |
50
|
|
|
|
51
|
|
|
// Required ability attributes |
52
|
|
|
'name' => $name = $this->argument('name') ?: $this->ask(Lang::get('rinvex.fort::artisan.ability.name')), |
|
|
|
|
53
|
|
|
'slug' => $this->argument('slug') ?: Str::slug($name), |
|
|
|
|
54
|
|
|
|
55
|
|
|
// Optional ability attributes |
56
|
|
|
'description' => $this->option('description'), |
57
|
|
|
|
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
$rules = [ |
61
|
|
|
'name' => 'required|max:255', |
62
|
|
|
'slug' => 'required|max:255|alpha_dash|unique:'.config('rinvex.fort.tables.abilities'), |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
$validator = app(Factory::class)->make($data, $rules); |
66
|
|
|
|
67
|
|
|
if ($validator->fails()) { |
68
|
|
|
$this->error('Errors:'); |
69
|
|
|
|
70
|
|
|
foreach ($validator->errors()->getMessages() as $key => $messages) { |
71
|
|
|
$this->error('- '.$key.': '.$messages[0]); |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
|
|
$ability = $this->laravel['rinvex.fort.ability']->create($data); |
75
|
|
|
|
76
|
|
|
$this->info(Lang::get('rinvex.fort::artisan.ability.created').' ['.Lang::get('rinvex.fort::artisan.ability.id').': '.$ability->id.', '.Lang::get('rinvex.fort::artisan.ability.name').': '.$ability->name.', '.Lang::get('rinvex.fort::artisan.ability.slug').': '.$ability->slug.']'); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.