Model::find($id);
That will find the row by the id for whichever Model you are trying to use. It will return an instance of the Model.
Is that what you are looking for?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm working w/ Dingo/Fractal and have an Eloquent model collection that I need to pass into my transformer. Based on URL params, I need to in/exclude joins in my Eloquent query. I start off w/ something like this:
$myModel = Model::
In this part I run into my first issue: Since I know I might be doing a join, I can't call a where (yet, as far as I know) on the Model:: and don't know what else to include (I've tried Model::select).
The solution is to use the Query Builder:
$myModel = DB::table('model');
The problem with this is it returns an Array, instead of a Collection and the transformer is expecting a collection of Model's.
What's the best option here? Is there something I'm missing? I did also try calling collect($myModel), but it returns a collection of StdClass, instead of Model.
// Full Query Example
$myModel = Model::select('model.id', 'model.name');
if ($request->has('example_param') {
$myModel->join('example_join_table AS ejt', 'model.id', '=', 'ejt.model_id')
}
$myModel->where('deleted', 0)->get()
Please or to participate in this conversation.