且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel:未定义变量:RoomTypes(视图:

更新时间:2023-02-22 14:23:28

我会尝试以下操作:

public function getCheckout(Request $request)
{
    if (!Session::has('cart')) {
        return view('shop.shopping-cart');
    }

    $RoomTypes = Room::all();
    $userInputRoomTypes = $request->input('RoomTypes'); // Renamed var to avoid overwriting $RoomTypes

    // ... 

    return view('posts.checkout', [
        'total'              => $total,
        'checkIn'            => $checkIn,
        'checkOut'           => $checkOut,
        'RoomTypes'          => $RoomTypes,
        'userInputRoomTypes' => $userInputRoomTypes,
    ]);
}

最后,这可能在您的HTML中起作用.不太确定要通过传递回请求数据来实现什么目的,但是如果要选择一个选项:

Finally, this might work inside your HTML. Not really sure what you are trying to achieve by passing the request data back, but if you want to select an option:

<select name="RoomType" id="RoomType" class="form-control input-lg dynamic" data-dependent="state">
    <option value="">Room type</option>

    @foreach($RoomTypes as $RoomType)
        <option value="{{$RoomType}}" {{ !old('RoomType', request('RoomType')) === $RoomType ?: 'selected' }}>{{$RoomType}}</option>
    @endforeach
</select>