Completed
Push — master ( ad6735...e5e602 )
by ARCANEDEV
05:41
created

RoleFormRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A sanitize() 0 8 2
1
<?php namespace Arcanesoft\Auth\Http\Requests\Backend\Roles;
2
3
use Arcanesoft\Auth\Bases\FormRequest;
4
use Arcanesoft\Auth\Models\Permission;
5
use Arcanesoft\Auth\Models\Role;
6
7
/**
8
 * Class     RoleFormRequest
9
 *
10
 * @package  Arcanesoft\Auth\Http\Requests\Backend\Roles
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
abstract class RoleFormRequest extends FormRequest
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Main Functions
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Get the validation rules that apply to the request.
21
     *
22
     * @return array
23
     */
24
    public function rules()
25
    {
26
        return [
27
            'name'        => 'required|min:3',
28
            'slug'        => 'required|min:3|unique:roles,slug',
29
            'description' => 'required|min:10',
30
            'permissions' => 'required|array|in:' . Permission::getIds()->implode(','),
31
        ];
32
    }
33
34
    /**
35
     * Sanitize the inputs.
36
     *
37
     * @param  array  $inputs
38
     *
39
     * @return array
40
     */
41
    public function sanitize(array $inputs)
42
    {
43
        $inputs['slug'] = (new Role)->makeSlugName(
44
            $this->get($this->has('slug') ? 'slug' : 'name')
45
        );
46
47
        return $inputs;
48
    }
49
}
50