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

RoleFormRequest::attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
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