StoreWardRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 14
c 2
b 0
f 1
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 16 1
A authorize() 0 6 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace App\Http\Requests;
5
6
use App\Models\Ward;
7
use Auth;
8
use Illuminate\Foundation\Http\FormRequest;
9
use Illuminate\Validation\Rule;
10
11
class StoreWardRequest extends FormRequest
12
{
13
    /**
14
     * Determine if the user is authorized to make this request.
15
     *
16
     * @return bool
17
     */
18
    public function authorize() : bool
19
    {
20
        $user = Auth::user();
21
        return
22
            $user->can("create", Ward::class) &&
23
            $user->can("update", Ward::class);
24
    }
25
26
    /**
27
     * Get the validation rules that apply to the request.
28
     *
29
     * @return array
30
     */
31
    public function rules() : array
32
    {
33
34
        $rules = [
35
            "name" => [
36
                "required",
37
                "min:3",
38
                "string",
39
                Rule::unique(Ward::getTableName())
40
                    ->where(function ($query) {
41
                        return $query->whereNull("deleted_at");
42
                    })
43
            ],
44
        ];
45
46
        return $rules;
47
    }
48
}
49