Php Laravel 4:使用雄辩的ORM模型获取特定字段
我对Laravel很陌生,有这样一个数据库Php Laravel 4:使用雄辩的ORM模型获取特定字段,php,laravel-4,eloquent,Php,Laravel 4,Eloquent,我对Laravel很陌生,有这样一个数据库 code | descriptor | id _______________________________________ frd Ford 1 chv Chevrolet 2 fer Ferrari 3 型号: class Car extends Eloquent {} 如何使用code查询以获取描述符 像这样: 从汽车中选择
code | descriptor | id
_______________________________________
frd Ford 1
chv Chevrolet 2
fer Ferrari 3
型号:
class Car extends Eloquent {}
如何使用code
查询以获取描述符
像这样:
从汽车中选择描述符,其中code='fer'
如拉威尔文档中所述,您可以在何处使用车型
$cars= Car::where('code', '=', 'fer')->get();
如果第二个参数为“=”则不是必须的
$cars= Car::where('code', 'fer')->get();
编辑:
如果您只需要单个列的数组,可以使用
如何仅获取
id
字段?使用->select('id')
代替->get
,但这取决于查询
$cars= DB::table('cars')->where('code', 'fer')->lists('id');