Laravel join 3 tables using Query Builder

I have a function that expects a query builder as input parameter. On the query I want all the records returned from this query:

$query = $model->newQuery()
->leftJoin('materials', 'products.material_id', '=', 'materials.id')
->leftJoin('vehicles', 'products.vehicle_id', '=', 'vehicles.id')
->leftJoin('parts', 'products.part_id', '=', 'parts.id')
->select(
'products.id as id',
'products.name as product_name',
'parts.part_name as part_name',
'materials.public_name as material',
'vehicles.name as vehicle'
);

Using leftJoin the function runs but returns nothing and if I replace leftJoin for join (what I think it's the right solution for this case) vsc says it's not a Query Builder and executing returns 5xx error.

$model binds to my Product model.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3eqDxZW
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

5 Free Black and White Social Media Icons Sets with CSS and HTML

How to Create Treeview with Bootstrap and jQuery

How to Change Apache and MySQL Port Number in XAMPP Localhost