1 | <?php |
||
8 | trait AttachesToUsers |
||
9 | { |
||
10 | /** |
||
11 | * Load the given user's shopping cart. |
||
12 | * |
||
13 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
14 | * @return static |
||
15 | */ |
||
16 | public function loadUserCart(Authenticatable $user): self |
||
33 | |||
34 | /** |
||
35 | * Attach the current cart to the given user. |
||
36 | * |
||
37 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
38 | * @return static |
||
39 | */ |
||
40 | public function attachTo(Authenticatable $user): self |
||
52 | |||
53 | /** |
||
54 | * Delete any old carts belonging to the given user and attach |
||
55 | * the current cart to them. |
||
56 | * |
||
57 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
||
58 | * @return static |
||
59 | */ |
||
60 | protected function overwrite(Authenticatable $user): self |
||
70 | } |
||
71 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.