I have a Notifications
model that belongs to a User
. I want to load the user when a collection of notifications is selected and only load the model with names
and emails
. However, when using the select method, the query returns null.
$notifications->load(['user' => function($query){
$query->select(["name","email"]);
}]);
If the parameter for select()
method is given as below, it gives all the fields:
$notifications->load(['user' => function($query){
$query->select(["*"]
}]);
Maybe selecting the fields like this works out:
$notifications->load('user:id,name,email');
What you are trying is designed to add constraints, not to select some fields
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With