Laravel Blade视图未显示从控制器传递的数据

时间:2019-02-11 04:58:01

标签: laravel laravel-blade

我有一个按钮,将显示基于特定ID的数据:

<td style="text-align: center; vertical-align:middle;">
  <a href="{{action('BookingController@payment', $book['booking_id'])}}" class="btn btn-secondary">Stripe Payment</a>&nbsp;        
</td>

路线为:

Route::get('payment/{id}', 'BookingController@payment')->middleware('verified');

BookingController @ pay是:

    public function payment($id)
{    
    $bookings= \App\Booking::find($id);
    return view('parking.payment')->with('bookings',$bookings);
}

刀片视图为:

<table class="table">
    <thead>
        <tr>
            <th style="text-align: center; vertical-align:middle;">Booking ID</th>
            <th style="text-align: center; vertical-align:middle;">Application Status</th>
            <th style="text-align: center; vertical-align:middle;">Semester</th>
            <th style="text-align: center; vertical-align:middle;">Parking Area</th>
            <th style="text-align: center; vertical-align:middle;">Parking Lot No.</th>
            <th style="text-align: center; vertical-align:middle;">Payment</th>
        </tr>
    </thead>   

    @foreach($bookings as $book)
    <tr>
        <td style="text-align: center; vertical-align:middle; color:red;">{{$book['booking_id']}}</td>
        <td style="text-align: center; vertical-align:middle;">{{$book['apply_status']}}</td>
        <td style="text-align: center; vertical-align:middle;">{{$book['semester']}}</td>
        <td style="text-align: center; vertical-align:middle;">{{$book['park_area']}}</td>
        <td style="text-align: center; vertical-align:middle;">{{$book['park_no']}}</td>
        <td style="text-align: center; vertical-align:middle;">{{$book['price']}}</td>
    </tr>
</table>
@endforeach

但是,刀片视图仅显示空白表。是因为数据与我在同一页面上创建的Stripe付款表单冲突?

1 个答案:

答案 0 :(得分:2)

$bookings = \App\Booking::find($id);将返回一个预订,但是根据您的命名和刀片视图中的循环,您似乎希望得到一个预订。也许您想要\App\Booking::where('booking_id', $id)->get()? (我不太清楚您的数据库结构)