laravel-favorite
laravel-favorite copied to clipboard
Eager load $article->isFavorited()
Detailed description
Hi there!
When i check if article is favorited by auth user
$article->isFavorited()
the debugbar gives me
Model: App\Models\Article => Relation: ChristianKuri\LaravelFavorite\Models\Favorite - You should add with(ChristianKuri\LaravelFavorite\Models\Favorite) to eager-load this relation.
wire controller
/**
* The read function.
* @return array
*/
public function read(): array
{
return [
'articles' => Article::search($this->search)
->with('user')
->where('status', true)
->latest()
->paginate($this->perPage),
];
}
public function render()
{
return view('livewire.front.article-wire', $this->read())->layout('layouts.app');
}
In Article model i tried
protected $with = ['favorites'];
but it didn't work
How could I eager load that?
Thanks!
- Laravel 9
- Livewire
don't think this is possible to eager load that query.