1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Requests\Admin\Profile; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Http\Requests\FormRequest; |
4
|
|
|
use Arcanesoft\Auth\Rules\OldPasswordRule; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class UpdatePasswordRequest |
8
|
|
|
* |
9
|
|
|
* @package Arcanesoft\Auth\Http\Requests\Admin\Profile |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class UpdatePasswordRequest extends FormRequest |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Main Methods |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Determine if the user is authorized to make this request. |
21
|
|
|
* |
22
|
|
|
* @return bool |
23
|
|
|
*/ |
24
|
|
|
public function authorize() |
25
|
|
|
{ |
26
|
|
|
/** @var \Arcanesoft\Contracts\Auth\Models\User $user */ |
27
|
|
|
$user = $this->route('auth_user'); |
28
|
|
|
|
29
|
|
|
return $user->id === auth()->user()->id; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the validation rules that apply to the request. |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function rules() |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
'old_password' => ['required', 'string', 'min:8', 'different:password', new OldPasswordRule(auth()->user())], |
|
|
|
|
41
|
|
|
'password' => ['required', 'string', 'min:8', 'different:old_password', 'confirmed'], |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set custom messages for validator errors. |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function messages() |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
|
|
'old_password.different' => trans('auth::profile.validation.password_different'), |
54
|
|
|
'password.different' => trans('auth::profile.validation.password_different'), |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/* ----------------------------------------------------------------- |
59
|
|
|
| Other Methods |
60
|
|
|
| ----------------------------------------------------------------- |
61
|
|
|
*/ |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the validated data. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function getValidatedData() |
69
|
|
|
{ |
70
|
|
|
return $this->only(['password']); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: