Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to filter out subject (favoriting) with null values. #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
9 changes: 8 additions & 1 deletion src/Traits/Favoriteable.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ public function isFavorited($user_id = null)
*/
public function favoritedBy()
{
return $this->favorites()->with('user')->get()->mapWithKeys(function ($item) {
$users = $this->favorites()->with('user')->get();
// dump($users);
$filtered = $users->filter(function($user){
return null !== $user->user;
});
$users = collect($filtered->values()->all());
// dd($users);
return $users->mapWithKeys(function ($item) {
return [$item['user']->id => $item['user']];
});
}
Expand Down