DEV Community

JohnDivam
JohnDivam

Posted on

1 1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay