how to select specific columns in laravel eloquent

2019-03-08 12:48发布

lets say I have 7 columns in table, and I want to select only two of them, something like this

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

In laravel eloquent model it may looks like this

Table::where('id', 1)->get();

but I guess this expression will select ALL columns where id equals 1, and I want only two columns(name, surname). how to select only two columns?

13条回答
爷的心禁止访问
2楼-- · 2019-03-08 13:26

Also Model::all(['id'])->toArray() it will only fetch id as array.

查看更多
登录 后发表回答