Reputation: 6622
I have been trying to figure out how to do a simple select where on a table for a few hours now. I was trying to follow this page but nothing I seem to try is working. Here is my model code with nothing in it.
<?php
namespace App\Models;
use BaseModel;
class Redemption extends BaseModel {
}
And here is the code I am trying to use in my controller.
$row = RedemptionModel::where('code', '=', Input::get('redemption_code'))->get();
var_dump($row);exit;
And here is the resulting data
object(Illuminate\Database\Eloquent\Collection)#162 (1) { ["items":protected]=> array(0) { } }
I know that the db is working fine and the model is working fine because if I do RedemptionModel::find(1)
that works. Also, if you know any good places to find ORM Laravel code with better examples please let me know.
Upvotes: 0
Views: 874
Reputation: 180024
get
fetches a Collection object, which is essentially an array of items, even if there's only one result. In other words, your $row
is actually row*s*.
If you want a single result, you can use first()
instead of get()
.
Upvotes: 1