with(‘user:Id,name’)
And you need the Id [foreign key] for the select otherwise there is nothing to relate
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, devs,
I usually use ->select method on query with ->with method in order to get only some properties from the model with relation only some properties.
But it doesn't work anymore for me.
Using Laravel 9.51
Here is my query:
Page::query()
->orderBy('updated_at')
->select('title', 'state', 'created_at', 'updated_at')
->get();
@hamzaelmaghari @michaloravec refers to user_id or whatever is the FK on the pages table
Page::query()
->orderBy('updated_at')
->select('id', 'title', 'state', 'created_at', 'updated_at', 'user_id')
->with('user:id,name')
->get();
which you need in order to reference the user model
Please or to participate in this conversation.