What is the relation between user and action?
Eloquent Serializing To Arrays Not Working
Hi guys I have a weird problem with my Laravel application.
I am trying to use eloquent serializing from an eloquent model. If I do this:
$action = App\Action::with(‘User’)->first();
return $action->toArray();
It returns me just the array of the Action model. It should give me the all relation with User. If I do this instead:
$action = App\Action::with(‘User’)->first();
return $action;
It returns the all eloquent model with the relation with User. So if I do $action->user->email it returns the user email.
I did this test to be sure the relationship is working.
I do not have now any ideas of why the function toArray() doesn't return the relation as well. I inserted the all User columns in the $visible variable as well, to make sure anything is being left out, but unfortunately still the same result.
What can be the problem? Is there a setting that I should know? In the documentation doesn't tell anything about, just about the $visible variable.
I tested this out. I had to add 'user' to the $visible array on the Action model. Then it worked fine.
Please or to participate in this conversation.