php - 如何从 Laravel 的某些表格中仅显示允许的车轮类型?
问题描述
我有一些表格,我只需要选择该区域允许的车轮类型,这是我的 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);
?>
我的区域类型:只有选定的车轮类型应该显示在区域中,我有桌子
- '轮子' => 'wheels_type_id'
- 'zones' => 'wheels_type_1' 到 'wheels_type_17'
- 'zone_wheels' => 'wheels_id'
解决方案
试试 str_limit, https: //laravel.com/docs/7.x/helpers#method-str-limit
例子:
use Illuminate\Support\Str;
$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20);
// The quick brown fox...
推荐阅读
- java - 如何使用 MockitoJUnitRunner 模拟 unmodifiableMap
- apache-spark - Spark 设备上没有剩余空间
- spring-boot - @Bean 配置的 bean 可以自动装配其他 bean 吗?
- asp.net - 使用 IdentityServer4 向 SSO 动态添加步骤
- python-xarray - 更改 xarray 数据集中的坐标
- swift - 在 Swift 4 中无法计算或迭代结构数组
- r - R中的函数给出ggplot输出错误
- python - SQLAlchemy 批量创建(如果不存在)
- utf-8 - 如何确定字符串的编码格式然后解码
- javascript - D3.js词云不显示无错误信息