How to select specific columns on a Model with array in Laravel

Categorized as Laravel Tagged

Hello friends. If you need to retrieve some specific columns from your Model, there is shorter way to do that. With this code, you can pass an array directly to the get method :

// 🤔 you could do it that way
Users::select(['name', 'title', 'email'])->get();


// ✅ you can do it this way
Users::get(['name', 'title', 'email']);

Leave a reply

Your email address will not be published. Required fields are marked *