1 | <?php |
||
9 | class DiscussCategory extends Model |
||
10 | { |
||
11 | use Sluggable, |
||
12 | DiscussCategoryPresenter; |
||
13 | |||
14 | /** |
||
15 | * The accessors to append to the model's array form. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $appends = [ |
||
20 | 'category_url' |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * The "booting" method of the model. |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | protected static function boot() |
||
37 | |||
38 | /** |
||
39 | * Return the field to slug. |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public function slugStrategy(): string |
||
47 | |||
48 | /** |
||
49 | * Get the conversations for the category. |
||
50 | * |
||
51 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
52 | */ |
||
53 | public function conversations() |
||
57 | |||
58 | /** |
||
59 | * Get the last conversation of the category. |
||
60 | * |
||
61 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
62 | */ |
||
63 | public function lastConversation() |
||
67 | |||
68 | /** |
||
69 | * Pluck the categories by the given fields and the locked state. |
||
70 | * |
||
71 | * @param string $value |
||
72 | * @param string|null $column |
||
73 | * |
||
74 | * @return \Illuminate\Support\Collection |
||
75 | */ |
||
76 | public static function pluckLocked($value, $column = null): Collection |
||
84 | } |
||
85 |
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: