How to select specific columns in laravel eloquent

Laravel 7

Nicesnippets

401

16-04-2020


Hello Friens,

Sometimes we required only some columns from many columns in table. if you have to select name and email then give both column name in select function. how to get specific column in get() function.

In PHP

SELECT `name`,`surname` FROM `table` WHERE `id` = '1';

In Laravel

TableName::select('name','surname')->where('id', 1)->get();

I hope it can help you...