How to return multi relations using eloquent

Edward Ziadeh • 19 March 2019
Blog in group Laravel
0 comments
0 likes

Example:

User created posts, news and articles.

With Laravel eloquent we can use with to add the relation.
It does work as following, if we do user with posts it will search in the post table for user_id.

$result = User::with('post')->get();

So if we need to get a multi relation we can do it this way:

$result = User::with('post', 'news', 'article')->get();

and if we do 

dd($result);

we should see in the JSON a relation that contain all of the resuts.