コード例 #1
0
ファイル: FavoritableTrait.php プロジェクト: huoybb/movie
 public function removeFavoriteBy(Users $user)
 {
     if ($user->hasFavoredThis($this)) {
         Favorites::query()->where('user_id = :user:'******'user' => $user->id])->andWhere('favoritable_type = :type:', ['type' => get_class($this)])->andWhere('favoritable_id = :id:', ['id' => $this->id])->execute()->delete();
     }
     return $this;
 }
コード例 #2
0
 public function favorites()
 {
     if (null == $this->favorites) {
         $this->favorites = Favorites::query()->where('user_id = :user:'******'user' => $this->id])->leftJoin('Movies', 'Movies.id = Favorites.favoritable_id AND favoritable_type = "Movies"')->orderBy('created_at DESC')->columns(['Favorites.id', 'Favorites.user_id', 'Favorites.favoritable_id AS movie_id', 'Favorites.created_at AS created_at', 'Movies.title AS movie_title'])->execute();
     }
     return $this->favorites;
 }