jeudi 19 octobre 2017

joining tables in laravel and get data by group

I have tables like below. I want to get the data which has count of unique make_id.

I joined all the tables and I'm getting error as 'Unexpected data found'.

leads:

+----+------------+
| id | vehicle_id |
+----+------------+
| 1  |     1      |
| 2  |     2      |
| 3  |     3      |
+----+------------+

vehicles

+----+------------+
| id | model_id   |
+----+------------+
| 1  |     1      |
| 2  |     2      |
| 3  |     3      |
+----+------------+

models:

+----+------------+
| id | make_id    |
+----+------------+
| 1  |     1      |
| 2  |     2      |
| 3  |     3      |
+----+------------+

This is my code:

$Leads = Leads::join('vehicles', 'vehicles.id', '=', 'leads.vehicle_id')
        ->join('models', 'models.id', '=', 'vehicles.model_id')
->groupBy('vehicles.model_id')
->get();

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire