koel/app/Repositories/InteractionRepository.php

33 lines
658 B
PHP
Raw Normal View History

2018-08-29 13:15:11 +07:00
<?php
namespace App\Repositories;
use App\Models\Interaction;
use App\Models\User;
use App\Repositories\Traits\ByCurrentUser;
use Illuminate\Support\Collection;
class InteractionRepository extends AbstractRepository
{
use ByCurrentUser;
public function getModelClass(): string
{
return Interaction::class;
}
/**
* Get all songs favorited by a user.
*/
public function getUserFavorites(User $user): Collection
{
return $this->model->where([
'user_id' => $user->id,
'like' => true,
])
->with('song')
->get()
->pluck('song');
}
}