1 | <?php |
||
12 | class EnrollmentDeleteRequest extends FormRequest |
||
13 | { |
||
14 | /** |
||
15 | * Determine if the user is authorized to make this request. |
||
16 | * |
||
17 | * @return bool |
||
18 | */ |
||
19 | public function authorize() |
||
20 | { |
||
21 | return Auth::user()->can('delete enrollments'); |
||
|
|||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Get the validation rules that apply to the request. |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | public function rules() |
||
30 | { |
||
31 | return [ |
||
32 | |||
33 | ]; |
||
34 | } |
||
35 | |||
36 | public function forbiddenResponse() |
||
40 | } |
||
41 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: