Skip to content
Advertisement

Relationship eloquent in laravel?

In user:

JavaScript

In post:

JavaScript

I handle in controller:

JavaScript

Then I get an array and the result returned is exactly what I need.

But when I query this way because I need to get a lot of data, the result is an empty array. What did I do wrong?

In UserController.php:

JavaScript

Please give me any comments.

Advertisement

Answer

You have to select foreign key in posts:

JavaScript

or

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement