Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kekekiw123's avatar

select() and get() difference

I wonder what the difference between get() and select() is.

I am using ->paginate(15); to paginate my result but I only need a few specific fields.

It got not work with ->get('some_field', 'another_field'); but when I do >select('some_field', 'another_field'); it will work.

Is not get() the same as select ?

0 likes
5 replies
cipsas's avatar

no, get() is like get query result, select() - select specific columns

kekekiw123's avatar

@cipsas But I can use get to only select specific fields, eg ->get('field_one', 'field_two', 'field_three')

jekinney's avatar

Yes you can, but get() will over ride and relations and other selects befor it. In other words if your chaining anything in get with be all that's avalible.

usman's avatar
usman
Best Answer
Level 27

@kiwo123 the select method is used to set the columns to be selected, it is like just adding the select clause to the query. Whereas get executes the query as whole select statment and retreives the result. However the columns you set using the select get the higher preority and will not be replaced by following get call. I suggest you to run the following query on your user model and see for yourself ( L53 ):

DB::table('users')->select(['name'])->get(['id','email']);

Usamn.

pmall's avatar

$query->get('something') is a shortcut for $query->select('something')->get()

Please or to participate in this conversation.