Completed
Push — master ( 1bcff9...3c7575 )
by ARCANEDEV
04:01
created

RoleFormRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 72
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A attributes() 0 6 1
A sanitize() 0 8 2
A getSlugRule() 0 4 1
A getRolesTable() 0 4 1
1
<?php namespace Arcanesoft\Auth\Http\Requests\Admin\Roles;
2
3
use Arcanesoft\Auth\Http\Requests\FormRequest;
4
use Arcanesoft\Auth\Models\Permission;
5
use Arcanesoft\Auth\Models\Role;
6
use Illuminate\Validation\Rule;
7
8
/**
9
 * Class     RoleFormRequest
10
 *
11
 * @package  Arcanesoft\Auth\Http\Requests\Admin\Roles
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
abstract class RoleFormRequest extends FormRequest
15
{
16
    /* -----------------------------------------------------------------
17
     |  Main Methods
18
     | -----------------------------------------------------------------
19
     */
20
    /**
21
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules()
26
    {
27
        return [
28
            'name'        => ['required', 'min:3'],
29
            'slug'        => ['required', 'min:3', $this->getSlugRule()],
30
            'description' => ['required', 'min:10'],
31
            'permissions' => ['required', 'array', 'in:'.Permission::getIds()->implode(',')],
32
        ];
33
    }
34
35
    /**
36
     * Get custom attributes for validator errors.
37
     *
38
     * @return array
39
     */
40
    public function attributes()
41
    {
42
        return [
43
            'permissions' => trans('auth::permissions.titles.permissions')
44
        ];
45
    }
46
    /* -----------------------------------------------------------------
47
     |  Other Methods
48
     | -----------------------------------------------------------------
49
     */
50
    /**
51
     * Sanitize the inputs.
52
     *
53
     * @return array
54
     */
55
    protected function sanitize()
56
    {
57
        return [
58
            'slug' => (new Role)->makeSlugName(
59
                $this->get($this->has('slug') ? 'slug' : 'name')
60
            )
61
        ];
62
    }
63
64
    /**
65
     * Get the slug rule.
66
     *
67
     * @param  string  $column
68
     *
69
     * @return \Illuminate\Validation\Rules\Unique
70
     */
71
    protected function getSlugRule($column = 'slug')
72
    {
73
        return Rule::unique($this->getRolesTable(), $column);
74
    }
75
76
    /**
77
     * Get the roles table name.
78
     *
79
     * @return string
80
     */
81
    protected function getRolesTable()
82
    {
83
        return $this->getPrefixTable().config('arcanesoft.auth.roles.table', 'roles');
84
    }
85
}
86