Example #1
0
File: Song.php Project: tamdao/koel
 /**
  * Get all songs favored by a user.
  *
  * @param User $user
  * @param bool $toArray
  *
  * @return \Illuminate\Database\Eloquent\Collection|array
  */
 public static function getFavorites(User $user, $toArray = false)
 {
     $songs = Interaction::where(['user_id' => $user->id, 'liked' => true])->with('song')->get()->pluck('song');
     return $toArray ? $songs->toArray() : $songs;
 }