morphTo(); } /** * Increment the current user's view count for the given viewable model. */ public static function incrementFor(Viewable $viewable): int { $user = user(); if (is_null($user) || $user->isDefault()) { return 0; } /** @var View $view */ $view = $viewable->views()->firstOrNew([ 'user_id' => $user->id, ], ['views' => 0]); $view->save(['views' => $view->views + 1]); return $view->views; } /** * Clear all views from the system. */ public static function clearAll() { static::query()->truncate(); } }