У меня есть несколько таблиц, мне нужно выбрать только тот тип колес, который разрешен в зоне, это мой код запроса Laravel:
<?php
$wheels = DB::table('wheels')
->join('users', 'users.id', '=', 'wheels.user_id')
->join('wheels_types', 'wheels_types.id', '=', 'wheels.wheels_type_id')
->join('zone_wheels', 'zone_wheels.wheels_id', '=', 'wheels.id')
->leftjoin('zones', function($join){
$join->on('zones.wheels_type_1','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_2','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_3','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_4','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_5','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_6','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_7','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_8','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_9','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_10','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_11','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_12','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_13','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_14','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_15','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_16','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
$join->orOn('zones.wheels_type_17','=','wheels.wheels_type_id'); // i want to join the users table with either of these columns
})
->where('zone_wheels.zone_id', $this->id)
->where('zone_wheels.is_approved', true)
->whereNull('zone_wheels.deleted_at')
->select(
'wheels.id AS wheels_id',
'wheels.user_id AS user_id',
'wheels.name AS name',
'wheels.price AS price',
'users.email AS contact',
'wheels.city AS city',
'wheels.model AS model',
'users.fb_certified AS fb_certified',
'users.paid_certified AS paid_certified',
'wheels_types.name_en AS type',
'wheels.status AS status',
'wheels.zipcode AS zipcode',
'wheels.base_city AS base_city',
'wheels.description AS description')
->orderBy('wheels.updated_at', 'desc')
->paginate(12);
?>
Мои типы зон: на выбранных типах колес должны отображаться только зона, у меня есть таблицы
- 'wheel' => 'wheel_type_id'
- 'zone' => 'wheel_type_1' до 'wheel_type_17'
- 'zone_wheels' = > 'wheel_id'