Some refactors

This commit is contained in:
Phan An 2017-05-02 00:36:42 +07:00
parent 2e59ab0bb1
commit fb49cd6fb1
No known key found for this signature in database
GPG key ID: 4AF3D4E287BF423F
2 changed files with 3 additions and 6 deletions

View file

@ -130,11 +130,11 @@ class Interaction extends Model
*/
public static function batchUnlike(array $songIds, User $user)
{
foreach (self::whereIn('song_id', $songIds)->whereUserId($user->id)->get() as $interaction) {
self::whereIn('song_id', $songIds)->whereUserId($user->id)->get()->each(function ($interaction) {
$interaction->liked = false;
$interaction->save();
event(new SongLikeToggled($interaction));
}
});
}
}

View file

@ -244,10 +244,7 @@ class Song extends Model
*/
public static function getFavorites(User $user, $toArray = false)
{
$songs = Interaction::where([
'user_id' => $user->id,
'liked' => true,
])
$songs = Interaction::whereUserIdAndLike($user->id, true)
->with('song')
->get()
->pluck('song');