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
|
|
|
$model = resolve('App\\User'); |
18
|
|
|
$user = $model::find($this->route('user')); |
19
|
|
|
return $user && auth()->user()->can('update', $user); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get the validation rules that apply to the request. |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public function rules() |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
'name' => ['required', 'string'], |
31
|
|
|
'email' => ['required', 'string', 'unique:users,email,' . $this->route('user')], |
32
|
|
|
'auth_password' => ['nullable', 'required_with:password', 'string', function ($attribute, $value, $fail) { |
33
|
|
|
if (!Hash::check($value, auth()->user()->password)) { |
|
|
|
|
34
|
|
|
$fail(trans('auth.failed')); |
35
|
|
|
} |
36
|
|
|
}], |
37
|
|
|
'password' => ['nullable', 'required_with:auth_password', 'string', 'min:8', 'confirmed'], |
38
|
|
|
'role_id' => ['required', 'string', 'exists:roles,id'], |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get custom messages for validator errors. |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function messages() |
48
|
|
|
{ |
49
|
|
|
return trans('microboard::users.fields'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: