Guys,
I have the following scenario:
- I need to filter the latest version for each type.
My Collection is called Template, for the template I have the following columns in the DB:
variant (int)
version (int)
id_type(int)
For the given table data:
Row........: 1-----2-----3-----4-----5-----6
id_Type...: 1-----1-----1-----2-----2-----2
Variant....: 1-----1-----2-----1-----1-----1
Version...: 1-----2-----1-----1-----2-----3
So if i have the example above with 6 results i want the latest version of each variant and grouped by type (3 items in this case), my results would return only the following records:
Row........: 2-----3-----6
id_Type...: 1-----1-----2
Variant....: 1-----2-----1
Version...: 2-----1-----3
Wondering if anyone could help to create that query using the Eloquent/Query Builder
Today this is what i have, returns all the data the variants and versions.
$this->tableData = Template::leftJoin('qual_form_templates', 'template_templates.id', '=', 'qual_form_templates.template_id')
->with('type')
->select('template_templates.*', 'qual_form_templates.approved')
->get();
Thanks