| 1 | <?php |
||
| 13 | class EnrollmentBrowseRequest extends FormRequest |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Determine if the user is authorized to make this request. |
||
| 17 | * |
||
| 18 | * @return bool |
||
| 19 | */ |
||
| 20 | public function authorize() |
||
| 21 | { |
||
| 22 | return Auth::user()->can('browse enrollments'); |
||
|
|
|||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Get the validation rules that apply to the request. |
||
| 27 | * |
||
| 28 | * @return array |
||
| 29 | */ |
||
| 30 | public function rules() |
||
| 36 | |||
| 37 | public function forbiddenResponse() |
||
| 41 | } |
||
| 42 |
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: