为了账号安全,请及时绑定邮箱和手机立即绑定

如何检查多列?

如何检查多列?

PHP
慕沐林林 2021-04-06 17:18:00
我需要检查是否schedules_id等于请求,schedules_id然后需要检查profile“已预订”或“待定”,然后需要将所有“已预订”的profile seat值传递到blade.php中。我该怎么做,或者是否有其他方法或逻辑来做到这一点,请告诉我我是Laravel的新手我现在如何获取数据:class PassengersController extends Controller{    public function booking(Request $request)    {        //river is used to pass important params with flow of it from page to page        $seat         = $request->seat;        $buses_id     = $request->buses_id;        $schedules_id = $request->schedules_id;        $data         = Buses::where('buses_id', $buses_id)->first();        $seat         = json_decode($data->seat_layout, true);        $front        = json_decode($data->front_layout, true);        $bookingSeat  = Bookings::whereColumn('schedules_id', 'schedules_id')->get();        $bookingSeat = $bookingSeat->map(function ($bookSeat) {            $bookSeat->seat = explode(",", $bookSeat->seat);            return $bookSeat;        });        return view('frontend.booking', ['seat' => $seat, 'buses_id' => $buses_id, 'schedules_id' => $schedules_id, 'front' => $front, 'bookingSeet' => $bookingSeat]);    }}blade.php<div class="bus">@foreach($seat as $key => $item)@foreach($bookingSeet as $seer)   <div class="col-md-1">   <div class="seats back seats    @if(in_array($item['name'], $seer['seat']))   activeSeat   @endif"   data-id="{{$key}}">   <div class="special-attributes"></div>   @if(isset($item['name'])){{$item['name']}}@else 11A @endif   <input type="checkbox" name="seat_id[]" id="{{$key}}" value="{{$key}}">   </div>   </div>@endforeach@endforeach</div>桌子bookings_id users_id schedules_id buses_id routes_id seat price profile    1           1         6           1       3        1  Null  pending    2           1         6           1       3        2  Null  booked    3           1         6           1       3        3  null  booked我当前代码的问题是在所有预订表列中获取2个数组,如何在我尝试将ex的复选框复制到刀片时,将该值传递给刀片服务器。一辆巴士有50个座位,但现在显示100个座位。像1,1,2,2这样的座位
查看完整描述

3 回答

?
慕斯709654

TA贡献1840条经验 获得超5个赞

您可以在任何地方使用数组als。


例如:


$model->where([

      ['field-one', '=', 'valueOne'],

      ['field-two', '=', 'valueY']

]);


查看完整回答
反对 回复 2021-04-23
?
Qyouu

TA贡献1786条经验 获得超11个赞

试试这个:


$bookingSeat  = Bookings::where('schedules_id', $request->schedules_id)->where(function ($q) {

    $q->where('profile', 'booked')->orWhere('profile', 'pending');

})->get();

或这个:


$profileTypes = ['booked', 'pending'];

$bookingSeat  = Bookings::where('schedules_id', $request->schedules_id)->whereIn('profile', $profileTypes)->get();

@编辑


这样,如果您的预订表包含所有已注册(1至50)的座位,它将返回您的个人资料针对特定公交车,路线和时间“预订”或“待定”的所有座位。


$profileTypes = ['booked', 'pending'];

$bookingSeat  = Bookings::where('schedules_id', $request->schedules_id)

    ->whereIn('profile', $profileTypes)

    ->where('buses_id', $buses_id)

    ->where('routes_id', $request->route_id)

    ->get();


查看完整回答
反对 回复 2021-04-23
?
慕慕森

TA贡献1856条经验 获得超17个赞

试试这个

Bookings::where('schedules_id', $schedules_id)->where('profile', 'booked')->get();


查看完整回答
反对 回复 2021-04-23
  • 3 回答
  • 0 关注
  • 156 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信