【发布时间】:2018-03-21 17:27:51
【问题描述】:
我有两张桌子
women-dress
women-dress_attributes
women-dress 有 price 、 color 和 women-dress_attributes 有 display_name 、 attribute_name 和 filter
filter 是一个简单的 Y 或 N 值women-dress_attributes 中的一行看起来像
Price price Y
由于价格的过滤值为 Y,我需要从 women-dress 加载不同的 price 值
我的控制器的一部分看起来像这样
$Filter_query = DB::table($attribute_table_name)
->select('display_name','attribute')
->where('filter', '=', 'Y')
->get();
在我的刀片文件中,我有
@foreach($Filter_query as $agm)
<h4>{{ $agm->display_name }}</h4>
@endforeach
现在我如何运行另一个 sql select distinct 查询来加载刀片文件中的相应值?
或者有没有更好的做法?
【问题讨论】:
-
这样的东西对你有用 $Filter_query = DB::table('women-dress') ->join('women-dress_attributes','women-dress_attributes.women-dress_id',' =','women-dress.id') ->distinct('women-dress.price') ->where('women-dress_attributes.filter', '=', 'Y') ->get();
标签: sql laravel select distinct blade