How to select specific columns in laravel eloquent

10-Apr-2023

.

Admin

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...

#Laravel 7