This don't work:
$object = Model::find($id);
This works:
$object = Model::where('id', '=', $id)->first();
It doesn't make sense. Am I missing something? I'm using Laravel 5.2.36.
This don't work:
$object = Model::find($id);
This works:
$object = Model::where('id', '=', $id)->first();
It doesn't make sense. Am I missing something? I'm using Laravel 5.2.36.
id
needs to be a primary key, see:
https://laravel.com/api/5.2/Illuminate/Database/Eloquent/Model.html#method_find
I had the same problem. I sorted out it, using the function intval()
to transform $id
to an integer
value:
$id = intval($id);
$object = Model::find($id);
public $primaryKey = 'id';
make it a primary key in your model file or you can use
Model::firstOrNew(['id' => $id]);
but here id should be a fillable property in the model. for example
protected $fillable = ['id'];