1 | <?php |
||
9 | trait UserSocialite |
||
10 | { |
||
11 | /** |
||
12 | * User socials relationship. |
||
13 | * |
||
14 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
15 | */ |
||
16 | 42 | public function socials() |
|
22 | |||
23 | /** |
||
24 | * Check social network is attached to user. |
||
25 | * |
||
26 | * @param $slug |
||
27 | * @return mixed |
||
28 | */ |
||
29 | 9 | public function isAttached(string $slug): bool |
|
33 | |||
34 | /** |
||
35 | * Attach social network provider to the user. |
||
36 | * |
||
37 | * @param SocialProvider $social |
||
38 | * @param string $socialId |
||
39 | * @param string $token |
||
40 | * @param int $expiresIn |
||
41 | */ |
||
42 | 24 | public function attachSocial($social, string $socialId, string $token, int $expiresIn = null) |
|
58 | |||
59 | /** |
||
60 | * @param User $socialUser |
||
61 | * @return array |
||
62 | */ |
||
63 | 6 | public function mapSocialData(User $socialUser) |
|
78 | |||
79 | /** |
||
80 | * Get model email field name. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 21 | public function getEmailField(): string |
|
88 | } |
||
89 |
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.