App\Models\Forum\Topic::markRead PHP Method

markRead() public method

public markRead ( $user, $markTime )
    public function markRead($user, $markTime)
    {
        if ($user === null) {
            return;
        }
        $status = TopicTrack::where(['user_id' => $user->user_id, 'topic_id' => $this->topic_id]);
        if ($status->first() === null) {
            // first time seeing the topic, create tracking entry
            // and increment views count
            TopicTrack::create(['user_id' => $user->user_id, 'topic_id' => $this->topic_id, 'forum_id' => $this->forum_id, 'mark_time' => $markTime]);
            $this->increment('topic_views');
        } elseif ($status->first()->mark_time < $markTime) {
            // laravel doesn't like composite key ;_;
            // and the setMarkTimeAttribute doesn't work here
            $status->update(['mark_time' => $markTime->getTimeStamp()]);
        }
        if ($this->topic_last_view_time < $markTime) {
            $this->topic_last_view_time = $markTime;
            $this->save();
        }
    }