Sql larave:当计数达到给定值时,如何从foreach循环中删除选定的数据
俯视 我正在使用预约系统,但所有时段都是开放的。预约没有限制。当所选时段的预订数量达到25时,我想隐藏/禁用所选时段 这是我的变量,用于每个Sql larave:当计数达到给定值时,如何从foreach循环中删除选定的数据,sql,laravel,foreach,laravel-8,Sql,Laravel,Foreach,Laravel 8,俯视 我正在使用预约系统,但所有时段都是开放的。预约没有限制。当所选时段的预订数量达到25时,我想隐藏/禁用所选时段 这是我的变量,用于每个 @php $times = DB::table('times') ->where('app_id', $app->id) ->get(); @endphp 我就是这样 @foreach ($times as $item) @php $blocktime = DB::table('bookings')->where('app_id
@php
$times = DB::table('times')
->where('app_id', $app->id)
->get();
@endphp
我就是这样
@foreach ($times as $item)
@php
$blocktime = DB::table('bookings')->where('app_id',$app->id)
->where('time',$item->time)
->where('status',1)->get();
@endphp
<div class="col-md-3" style="padding-bottom: 10px;">
<label class="btn btn-outline-primary">
<input type="radio" name="time" value="{{ $item->time }}">
<span>{{ $item->time }}</span>
</label>
</div>
@endforeach
当$blocktime
计数达到25时,我想禁用特定的时间段,我如何才能做到这一点
感谢您宝贵的时间从您的问题中我可以得到,您不需要显示alredy有25个
预订的时间
您只需要使用count()
而不是get()
,如果大于24,则使用continue
@foreach ($times as $item)
@php
$blocktime = DB::table('bookings')->where('app_id',$app->id)
->where('time',$item->time)
->where('status',1)->count();
if ($blocktime > 24) {
continue;
}
@endphp
<div ....>
</div>
@endforeach
@foreach($times as$item)
@php
$blocktime=DB::table('bookings')->where('app_id',$app->id)
->其中('time',$item->time)
->其中('status',1)->count();
如果($blocktime>24){
继续;
}
@endphp
@endforeach
我还没有测试代码,希望它能工作。从你的问题中我可以得到,你不需要显示alredy有25个预订的时间
您只需要使用count()
而不是get()
,如果大于24,则使用continue
@foreach ($times as $item)
@php
$blocktime = DB::table('bookings')->where('app_id',$app->id)
->where('time',$item->time)
->where('status',1)->count();
if ($blocktime > 24) {
continue;
}
@endphp
<div ....>
</div>
@endforeach
@foreach($times as$item)
@php
$blocktime=DB::table('bookings')->where('app_id',$app->id)
->其中('time',$item->time)
->其中('status',1)->count();
如果($blocktime>24){
继续;
}
@endphp
@endforeach
我还没有测试代码,希望它能工作。根据我对您的查询的了解,如果$blocktime=25,您希望禁用包含一个时间段的单选按钮,因此您可以执行以下操作来实现此目的:
@foreach ($times as $item)
@php
$breakTime = false;
$blocktime = DB::table('bookings')->where('app_id',$app->id)
->where('time',$item->time)
->where('status',1)->count();
if ($blocktime == 25) {
$breakTime = true;
continue;
}
@endphp
<div class="col-md-3" style="padding-bottom: 10px;">
<label class="btn btn-outline-primary">
<input type="radio" name="time" value="{{ $item->time }}" {{($breakTime == true) ? 'disable' : ''}}>
<span>{{ $item->time }}</span>
</label>
</div>
@endforeach
@foreach($times as$item)
@php
$breakTime=false;
$blocktime=DB::table('bookings')->where('app_id',$app->id)
->其中('time',$item->time)
->其中('status',1)->count();
如果($blocktime==25){
$breakTime=true;
继续;
}
@endphp
{{$item->time}
@endforeach
根据我对您的查询的理解,如果$blocktime=25,您希望禁用包含一个时间段的单选按钮,因此您可以执行以下操作来实现此目的:
@foreach ($times as $item)
@php
$breakTime = false;
$blocktime = DB::table('bookings')->where('app_id',$app->id)
->where('time',$item->time)
->where('status',1)->count();
if ($blocktime == 25) {
$breakTime = true;
continue;
}
@endphp
<div class="col-md-3" style="padding-bottom: 10px;">
<label class="btn btn-outline-primary">
<input type="radio" name="time" value="{{ $item->time }}" {{($breakTime == true) ? 'disable' : ''}}>
<span>{{ $item->time }}</span>
</label>
</div>
@endforeach
@foreach($times as$item)
@php
$breakTime=false;
$blocktime=DB::table('bookings')->where('app_id',$app->id)
->其中('time',$item->time)
->其中('status',1)->count();
如果($blocktime==25){
$breakTime=true;
继续;
}
@endphp
{{$item->time}
@endforeach