KrokettenHorst's avatar

what is the best way to select only specific colums from collection?

good morning ;)

What is the best way to select only certain columns of a large table from a performance perspective?

return MyView::where("foo", "bar")->get("col1", "col2", "col21", "col44");

or

return MyView::where("foo", "bar")->only("col1", "col2", "col21", "col44")->get();

or something else? and why?

0 likes
1 reply
Snapey's avatar

from collection or from database query?

If from collection then there is no performance gain if this is being used in blade

If from database then use ->select

MyView::where("foo", "bar")->select("col1", "col2", "col21", "col44")->get();

Please or to participate in this conversation.