App\Models\Forum\TopicWatch::toggle PHP Метод

toggle() публичный статический Метод

public static toggle ( $topic, $user, $isAdd )
    public static function toggle($topic, $user, $isAdd)
    {
        $function = $isAdd ? 'add' : 'remove';
        return forward_static_call_array([static::class, $function], [$topic, $user]);
    }

Usage Example

Пример #1
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'));
     }
 }