DEV Community

JohnDivam
JohnDivam

Posted on

Laravel 4Ways to Select specific columns

select specific columns from a database table using various methods provided by the Eloquent ORM (Object-Relational Mapping). Here are four common ways to select specific columns on a model:

$users = User::select('id', 'name')->get();
// or
$users = User::select(['id', 'name'])->get();
// or
$users = User::find(3,['id', 'name']);
// or
$users = User::get(['id', 'name']);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)