Completed
Push — master ( dd37c8...f1aff2 )
by ARCANEDEV
11s
created

UserRequest::getRolesRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Arcanesoft\Auth\Http\Requests\Backend\Users;
2
3
use Arcanesoft\Auth\Bases\FormRequest;
4
use Cache;
5
use Illuminate\Support\Str;
6
7
/**
8
 * Class     UserRequest
9
 *
10
 * @package  Arcanesoft\Auth\Http\Requests\Backend\Users
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
abstract class UserRequest extends FormRequest
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Main Functions
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Get all of the input and files for the request.
21
     *
22
     * @return array
23
     */
24
    public function all()
25
    {
26
        $username = Str::slug(
27
            $this->get('username'),
28
            config('arcanesoft.auth.slug-separator', '.')
29
        );
30
31
        return array_merge(parent::all(), compact('username'));
32
    }
33
34
    /* ------------------------------------------------------------------------------------------------
35
     |  Other Functions
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    /**
39
     * Get the roles rule.
40
     *
41
     * @return string
42
     */
43
    protected function getRolesRule()
44
    {
45
        return 'required|array|min:1|in:' . $this->getRoleIds()->implode(',');
46
    }
47
48
    /**
49
     * Get the role ids.
50
     *
51
     * @return \Illuminate\Database\Eloquent\Collection
52
     */
53
    private function getRoleIds()
54
    {
55
        return Cache::remember('auth.roles.ids', 5, function () {
56
            return app(\Arcanesoft\Contracts\Auth\Models\Role::class)->lists('id');
57
        });
58
    }
59
}
60