Reputation: 419
I'm very new to Laravel, having a database like this:
code | descriptor | id
_______________________________________
frd Ford 1
chv Chevrolet 2
fer Ferrari 3
Model:
class Car extends Eloquent {}
How do I query using the code
to get the descriptor
?
Like this:
SELECT descriptor FROM car WHERE code = 'fer'
Upvotes: 0
Views: 1984
Reputation: 2261
As stated in laravel's documentation you can use where with models
$cars= Car::where('code', '=', 'fer')->get();
And second paramater is not obligatory if it is '='
$cars= Car::where('code', 'fer')->get();
Edit:
If you just want an array of a single column you can use this
$cars= DB::table('cars')->where('code', 'fer')->lists('id');
Upvotes: 1