Laravel 6-如何在视图/刀片中从控制器的紧凑数组中获取值?

时间:2020-02-14 10:34:56

标签: php laravel

我正在使用控制器将紧凑型数组从刀片服务器传递到刀片服务器,我想在我的视图/刀片服务器模板中逐个访问它们,但是我总是收到此错误:

enter image description here

这是我的紧凑数组的内容:

enter image description here

这是来自 Controller 的代码段源代码:

//dd($flight_book_details);
    $flight_book_details = $request->all(); 
    return view('auth.register', compact('flight_book_details'));

这是我在视图 / 刀片模板中的摘录源代码:

<h2>
@foreach($flight_book_details as $flight_book_detail)
    {{$flight_book_detail->seat_quantity}}  //Trying to access the 'seat_quantity'
@endforeach
</h2>

问题:还有其他方法可以从视图中访问值吗?

2 个答案:

答案 0 :(得分:2)

如果您想访问'return': cannot convert from 'std::optional<int>' to 'bool',则不需要seat_quantity遍历它,

foreach

答案 1 :(得分:1)

您正在获取所有data.use数组。数据获取对象时使用的$ flight_book_details-> seat_quantity

{{$flight_book_details['seat_quantity']}}