Completed
Push — master ( d0984d...8e3192 )
by Jeremy
10:29 queued 05:27
created

StorePermissionRequest::permissionFillData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace jeremykenedy\LaravelRoles\App\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
7
class StorePermissionRequest extends FormRequest
8
{
9
    /**
10
     * Determine if the user is authorized to make this request.
11
     *
12
     * @return bool
13
     */
14
    public function authorize()
15
    {
16
        if (config('roles.rolesGuiCreateNewPermissionMiddlewareType') == 'role') {
17
            return $this->user()->hasRole(config('roles.rolesGuiCreateNewPermissionsMiddleware'));
18
        }
19
        if (config('roles.rolesGuiCreateNewPermissionMiddlewareType') == 'permissions') {
20
            return $this->user()->hasPermission(config('roles.rolesGuiCreateNewPermissionsMiddleware'));
21
        }
22
23
        return 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|max:60|unique:'.config('roles.permissionsTable').',name,'.$this->id.',id',
35
            'slug'          => 'required|max:60|unique:'.config('roles.permissionsTable').',slug,'.$this->id.',id',
36
            'description'   => 'nullable|string|max:255',
37
            'model'         => 'required|string|max:60',
38
        ];
39
    }
40
41
    /**
42
     * Return the fields and values to create a new role.
43
     *
44
     * @return array
45
     */
46
    public function permissionFillData()
47
    {
48
        return [
49
            'name'          => $this->name,
50
            'slug'          => $this->slug,
51
            'description'   => $this->description,
52
            'model'         => $this->model,
53
        ];
54
    }
55
}
56