1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the overtrue/laravel-follow. |
||
5 | * |
||
6 | * (c) overtrue <[email protected]> |
||
7 | * |
||
8 | * This source file is subject to the MIT license that is bundled |
||
9 | * with this source code in the file LICENSE. |
||
10 | */ |
||
11 | |||
12 | namespace Overtrue\LaravelFollow\Traits; |
||
13 | |||
14 | use Overtrue\LaravelFollow\Follow; |
||
15 | |||
16 | /** |
||
17 | * Trait CanBeFollowed. |
||
18 | */ |
||
19 | trait CanBeFollowed |
||
20 | { |
||
21 | /** |
||
22 | * Check if user is followed by given user. |
||
23 | * |
||
24 | * @param int $user |
||
25 | * |
||
26 | * @return bool |
||
27 | */ |
||
28 | public function isFollowedBy($user) |
||
29 | { |
||
30 | return Follow::isRelationExists($this, 'followers', $user); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Return followers. |
||
35 | * |
||
36 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
37 | */ |
||
38 | public function followers() |
||
39 | { |
||
40 | return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table')) |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
41 | ->wherePivot('relation', '=', Follow::RELATION_FOLLOW) |
||
42 | ->withPivot('followable_type', 'relation', 'created_at'); |
||
43 | } |
||
44 | } |
||
45 |