|
1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Requests\Admin\Users; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class UpdateUserRequest |
|
5
|
|
|
* |
|
6
|
|
|
* @package Arcanesoft\Auth\Http\Requests\Admin\Users |
|
7
|
|
|
* @author ARCANEDEV <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
class UpdateUserRequest extends UserFormRequest |
|
10
|
|
|
{ |
|
11
|
|
|
/* ----------------------------------------------------------------- |
|
12
|
|
|
| Main Methods |
|
13
|
|
|
| ----------------------------------------------------------------- |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Determine if the user is authorized to make this request. |
|
18
|
|
|
* |
|
19
|
|
|
* @return bool |
|
20
|
|
|
*/ |
|
21
|
|
|
public function authorize() |
|
22
|
|
|
{ |
|
23
|
|
|
return true; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get the validation rules that apply to the request. |
|
28
|
|
|
* |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
|
|
public function rules() |
|
32
|
|
|
{ |
|
33
|
|
|
/** @var \Arcanesoft\Contracts\Auth\Models\User $user */ |
|
34
|
|
|
$user = $this->route('auth_user'); |
|
35
|
|
|
|
|
36
|
|
|
return array_merge(parent::rules(), [ |
|
|
|
|
|
|
37
|
|
|
'username' => ['required', 'string', 'min:3', $this->getUsernameRule()->ignore($user->id)], |
|
|
|
|
|
|
38
|
|
|
'email' => ['required', 'string', 'email', $this->getEmailRule()->ignore($user->id)], |
|
|
|
|
|
|
39
|
|
|
'password' => ['nullable', 'string', 'required_with:password_confirmation', 'min:8', 'confirmed'], |
|
40
|
|
|
'password_confirmation' => ['nullable', 'string', 'required_with:password'], |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/* ----------------------------------------------------------------- |
|
45
|
|
|
| Other Methods |
|
46
|
|
|
| ----------------------------------------------------------------- |
|
47
|
|
|
*/ |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the validated data. |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getValidatedData() |
|
55
|
|
|
{ |
|
56
|
|
|
return array_filter( |
|
57
|
|
|
$this->only(['username', 'email', 'password', 'first_name', 'last_name']) |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.