猿问

如何检查多列?

我需要检查是否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这样的座位


慕沐林林
浏览 157回答 3
3回答

慕斯709654

您可以在任何地方使用数组als。例如:$model->where([&nbsp; &nbsp; &nbsp; ['field-one', '=', 'valueOne'],&nbsp; &nbsp; &nbsp; ['field-two', '=', 'valueY']]);

Qyouu

试试这个:$bookingSeat&nbsp; = Bookings::where('schedules_id', $request->schedules_id)->where(function ($q) {&nbsp; &nbsp; $q->where('profile', 'booked')->orWhere('profile', 'pending');})->get();或这个:$profileTypes = ['booked', 'pending'];$bookingSeat&nbsp; = Bookings::where('schedules_id', $request->schedules_id)->whereIn('profile', $profileTypes)->get();@编辑这样,如果您的预订表包含所有已注册(1至50)的座位,它将返回您的个人资料针对特定公交车,路线和时间“预订”或“待定”的所有座位。$profileTypes = ['booked', 'pending'];$bookingSeat&nbsp; = Bookings::where('schedules_id', $request->schedules_id)&nbsp; &nbsp; ->whereIn('profile', $profileTypes)&nbsp; &nbsp; ->where('buses_id', $buses_id)&nbsp; &nbsp; ->where('routes_id', $request->route_id)&nbsp; &nbsp; ->get();

慕慕森

试试这个Bookings::where('schedules_id',&nbsp;$schedules_id)->where('profile',&nbsp;'booked')->get();
随时随地看视频慕课网APP
我要回答