1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Microboard\Http\Requests\User; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
6
|
|
|
use Illuminate\Support\Facades\Hash; |
7
|
|
|
|
8
|
|
|
class UpdateFormRequest extends FormRequest |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Determine if the user is authorized to make this request. |
12
|
|
|
* |
13
|
|
|
* @return bool |
14
|
|
|
*/ |
15
|
|
|
public function authorize() |
16
|
|
|
{ |
17
|
|
|
return auth()->user()->can('update', $this->user); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get the validation rules that apply to the request. |
22
|
|
|
* |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function rules() |
26
|
|
|
{ |
27
|
|
|
return [ |
28
|
|
|
'name' => ['required', 'string'], |
29
|
|
|
'email' => ['required', 'string', 'unique:users,email,' . $this->user->id], |
|
|
|
|
30
|
|
|
'auth_password' => ['nullable', 'required_with:password', 'string', function($attribute, $value, $fail) { |
31
|
|
|
if (!Hash::check($value, auth()->user()->password)) { |
|
|
|
|
32
|
|
|
$fail(trans('auth.failed')); |
33
|
|
|
} |
34
|
|
|
}], |
35
|
|
|
'password' => ['nullable', 'required_with:auth_password', 'string', 'min:8', 'confirmed'], |
36
|
|
|
'role_id' => ['required', 'string', 'exists:roles,id'], |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get custom messages for validator errors. |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function messages() |
46
|
|
|
{ |
47
|
|
|
return trans('microboard::users.fields'); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.