RoleFormRequest::getRolesTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
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
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules()
27
    {
28
        return [
29
            'name'        => ['required', 'string', 'min:3'],
30
            'description' => ['required', 'string', '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
    /* -----------------------------------------------------------------
48
     |  Other Methods
49
     | -----------------------------------------------------------------
50
     */
51
52
    /**
53
     * Sanitize the inputs.
54
     *
55
     * @return array
56
     */
57
    protected function sanitize()
58
    {
59
        return [
60
            'slug' => (new Role)->makeSlugName(
61
                $this->get($this->has('slug') ? 'slug' : 'name')
62
            )
63
        ];
64
    }
65
66
    /**
67
     * Get the slug rule.
68
     *
69
     * @param  string  $column
70
     *
71
     * @return \Illuminate\Validation\Rules\Unique
72
     */
73
    protected function getSlugRule($column = 'slug')
74
    {
75
        return Rule::unique($this->getRolesTable(), $column);
76
    }
77
78
    /**
79
     * Get the roles table name.
80
     *
81
     * @return string
82
     */
83
    protected function getRolesTable()
84
    {
85
        return $this->getPrefixTable().config('arcanesoft.auth.roles.table', 'roles');
86
    }
87
}
88