S
S
SoloMidPlzD2016-08-03 23:00:57
ORM
SoloMidPlzD, 2016-08-03 23:00:57

How to do in Laravel Eager Loading User Favorited??

There is a bunch of news. The user can like them. 15 news are displayed on 1 page of news. Each one should show whether the user liked the news or not.
How to make eager loading so that the load is loaded and attached to the model? (the point is to make 1 request instead of 15)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Pochepko, 2016-08-03
@SoloMidPlzD

$user = User::with('favorites')->first();
'Favorites' is the name of the method that implements the association

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question