从控制器获取值并显示警报,因为至少有一个值应该处于活动状态

Get value from controller and show alert as atleast one value should be active

$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(活动),我想要一个 jquery 前端验证应该提醒我认为至少有一个状态在点击按钮时应该是 0(active)。任何人都可以帮助,如何做到这一点..谢谢

下面是我的查看代码

<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> 

您需要将查询修改为 return 状态为 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>