Наследование: extends Illuminate\Database\Eloquent\Model
Пример #1
0
 public function notifyReply($event)
 {
     $topic = $event->topic->fresh();
     $userIds = model_pluck(TopicWatch::where(['topic_id' => $topic->topic_id, 'notify_status' => false]), 'user_id');
     foreach (User::whereIn('user_id', $userIds)->get() as $user) {
         if (!present($user->user_email)) {
             continue;
         }
         if ($user->user_id === $topic->last_poster_id) {
             continue;
         }
         if (!priv_check_user($user, 'ForumTopicWatchAdd', $topic)->can()) {
             continue;
         }
         Mail::queue(['text' => i18n_view('emails.forum.new_reply')], compact('topic', 'user'), function ($message) use($topic, $user) {
             $message->to($user->user_email);
             $message->subject(trans('forum.email.new_reply', ['title' => $topic->topic_title]));
         });
         TopicWatch::where(['topic_id' => $topic->topic_id, 'user_id' => $user->user_id])->update(['notify_status' => true]);
     }
 }
Пример #2
0
 public function watch($id)
 {
     $topic = Topic::findOrFail($id);
     $state = get_bool(Request::input('watch'));
     $privName = 'ForumTopicWatch' . ($state ? 'Add' : 'Remove');
     $type = 'watch';
     priv_check($privName, $topic)->ensureCan();
     TopicWatch::toggle($topic, Auth::user(), $state);
     switch (Request::input('page')) {
         case 'manage':
             $topics = Topic::watchedByUser(Auth::user())->get();
             $topicReadStatus = TopicTrack::readStatus(Auth::user(), $topics);
             // there's currently only destroy action from watch index
             return js_view('forum.topic_watches.destroy', compact('topic', 'topics', 'topicReadStatus'));
         default:
             return js_view('forum.topics.replace_button', compact('topic', 'type', 'state'));
     }
 }
Пример #3
0
 public function scopeWatchedByUser($query, $user)
 {
     return $query->with('forum')->whereIn('topic_id', model_pluck(TopicWatch::where('user_id', $user->user_id), 'topic_id'))->orderBy('topic_last_post_time', 'DESC');
 }