Laravel (Eloquent) equivalent of Mongoose's populate() method Laravel (Eloquent) equivalent of Mongoose's populate() method mongoose mongoose

Laravel (Eloquent) equivalent of Mongoose's populate() method


If you have defined a posts() relationship in your User model, when retrieving the users, you can eager load the related data:

$users = User::with('posts')->get();

or a specific User:

$user = User::with('posts')->find($id);

Then $user->posts would contain a collection of the related Post models.

I suggest you read through https://laravel.com/docs/5.5/eloquent-relationships