1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPHub\Repositories\Eloquent; |
4
|
|
|
|
5
|
|
|
use PHPHub\Repositories\Eloquent\Traits\IncludeTopicTrait; |
6
|
|
|
use PHPHub\Transformers\IncludeManager\Includable; |
7
|
|
|
use PHPHub\Transformers\IncludeManager\IncludeManager; |
8
|
|
|
use PHPHub\User; |
9
|
|
|
use Prettus\Repository\Criteria\RequestCriteria; |
10
|
|
|
use PHPHub\Repositories\NotificationRepositoryInterface; |
11
|
|
|
use PHPHub\Notification; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class NotificationRepository. |
15
|
|
|
*/ |
16
|
|
|
class NotificationRepository extends BaseRepository implements NotificationRepositoryInterface |
17
|
|
|
{ |
18
|
|
|
use IncludeTopicTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* 生成一条新的 Notification. |
22
|
|
|
* |
23
|
|
|
* @param $attributes |
24
|
|
|
* |
25
|
|
|
* @return Notification |
26
|
|
|
*/ |
27
|
|
|
public function store($attributes) |
28
|
|
|
{ |
29
|
|
|
$notification = parent::create($attributes); |
|
|
|
|
30
|
|
|
User::whereId($notification->user_id)->increment('notification_count'); |
31
|
|
|
|
32
|
|
|
return $notification; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function includeFromUser($default_columns) |
36
|
|
|
{ |
37
|
|
|
$available_include = Includable::make('from_user') |
38
|
|
|
->setDefaultColumns($default_columns) |
39
|
|
|
->setAllowColumns(User::$includable) |
40
|
|
|
->setForeignKey('from_user_id'); |
41
|
|
|
|
42
|
|
|
app(IncludeManager::class)->add($available_include); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function includeReply($default_columns) |
46
|
|
|
{ |
47
|
|
|
$available_include = Includable::make('reply') |
48
|
|
|
->setDefaultColumns($default_columns) |
49
|
|
|
->setAllowColumns(User::$includable) |
50
|
|
|
->setForeignKey('reply_id'); |
51
|
|
|
|
52
|
|
|
app(IncludeManager::class)->add($available_include); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Specify Model class name. |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function model() |
61
|
|
|
{ |
62
|
|
|
return Notification::class; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Boot up the repository, pushing criteria. |
67
|
|
|
*/ |
68
|
|
|
public function boot() |
69
|
|
|
{ |
70
|
|
|
$this->pushCriteria(app(RequestCriteria::class)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* 用户最新的通知. |
75
|
|
|
* |
76
|
|
|
* @param $user_id |
77
|
|
|
* |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
|
|
public function userRecent($user_id) |
81
|
|
|
{ |
82
|
|
|
$this->model = $this->model |
83
|
|
|
->where(compact('user_id')) |
84
|
|
|
->orderBy('created_at', 'desc'); |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.