$selected_subcats = EstablishmnetSubcategories::Join('establishments','establishments.id','=','establishment_subcategories.establishment_id')->where('establishment_subcategories.created_by',Auth::User()->id)->get(array('establishment_subcategories.status as sub_status'));
这是我的控制器代码及其输出
[{"status":1},{"status":1},{"status":1},{"status":1},{"status":1},{"status":1},{"status":1},{"status":0}]
我有一个条件,例如,我需要从控制器检查状态,我有一个条件,如至少一个状态值应为0(active),我想要前端的jquery验证应提醒我至少一个状态应单击按钮时为0(有效)。谁能帮忙,如何完成..谢谢
下面的代码是我的视图代码
<td><a href="javascript:void;" class="label label-warning">{{$p->sub_status == 0 ? '<span class="label label-warning">Unpublish </span>' : '<span class="label label-warning">publish </span>'}}</a></td>
答案 0 :(得分:0)
您需要修改查询以返回状态为0(有效)的类别数
$activeCats = EstablishmnetSubcategories::Join('establishments','establishments.id','=','establishment_subcategories.establishment_id')
->where('establishment_subcategories.created_by',Auth::User()->id)
->where('establishment_subcategories.status',0)
->count();
html:
<td><a href="javascript:void;" class="label label-warning">{{$activeCats > 0 ? '<span class="label label-warning">Unpublish </span>' : '<span class="label label-warning">publish </span>'}}</a></td>