morphTo(); } public function jointPermissions(): HasMany { return $this->hasMany(JointPermission::class, 'entity_id', 'viewable_id') ->whereColumn('views.viewable_type', '=', 'joint_permissions.entity_type'); } /** * 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->forceFill(['views' => $view->views + 1])->save(); return $view->views; } }