Completed
Push — master ( caab36...1437d7 )
by ARCANEDEV
02:59
created

CreateRoleRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 59
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
A rules() 0 7 1
A all() 0 10 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
use Illuminate\Contracts\Validation\Validator;
7
8
/**
9
 * Class     CreateRoleRequest
10
 *
11
 * @package  Arcanesoft\Auth\Http\Requests\Backend\Roles
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class CreateRoleRequest extends FormRequest
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Properties
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Role validation rules.
22
     *
23
     * @var array
24
     */
25
    protected $rules = [
26
        'name'        => 'required|min:3',
27
        'slug'        => 'required|min:3|unique:roles,slug',
28
        'description' => 'required|min:10',
29
        'permissions' => 'required|array',
30
    ];
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Main Functions
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Determine if the user is authorized to make this request.
38
     *
39
     * @return bool
40
     */
41
    public function authorize()
42
    {
43
        return true;
44
    }
45
46
    /**
47
     * Get the validation rules that apply to the request.
48
     *
49
     * @return array
50
     */
51
    public function rules()
52
    {
53
        $rules                 = $this->rules;
54
        $rules['permissions'] .= '|in:' . Permission::getIds()->implode(',');
55
56
        return $rules;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function all()
63
    {
64
        $value = empty($this->get('slug'))
65
            ? $this->get('name')
66
            : $this->get('slug');
67
68
        return array_merge(parent::all(), [
69
            'slug' => (new Role)->makeSlugName($value)
70
        ]);
71
    }
72
}
73