1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Itstructure\LaRbac\Http\Requests; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class StorePermission |
9
|
|
|
* |
10
|
|
|
* @package Itstructure\LaRbac\Http\Requests |
11
|
|
|
* |
12
|
|
|
* @author Andrey Girnik <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class StorePermission extends FormRequest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Determine if the user is authorized to make this request. |
18
|
|
|
* |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
|
|
public function authorize() |
22
|
|
|
{ |
23
|
|
|
return !empty(config('rbac.routesMainPermission')) ? $this->user()->can(config('rbac.routesMainPermission')) : true; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get the validation rules that apply to the request. |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
public function rules() |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
'name' => 'required|string|regex:/^[\w\s\-]+$/|min:3|max:191|unique:permissions', |
35
|
|
|
'description' => 'required|string|min:3|max:191|unique:permissions', |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the error messages for the defined validation rules. |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function messages() |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
|
|
'required' => __('rbac::validation.required'), |
48
|
|
|
'string' => __('rbac::validation.string'), |
49
|
|
|
'regex' => __('rbac::validation.regex'), |
50
|
|
|
'min' => __('rbac::validation.min'), |
51
|
|
|
'max' => __('rbac::validation.max'), |
52
|
|
|
'unique' => __('rbac::validation.unique'), |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get custom attributes for validator errors. |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function attributes() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
'name' => __('rbac::main.name'), |
65
|
|
|
'description' => __('rbac::main.description'), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|