[英]How to call route with value in view Laravel 5.2?
我有一個數據表,當我單擊“數據ID”時,我想轉到詳細數據頁面
<td><a href= "{{ route('ReservationDetail') }}" >{{ $getData->ID }}</a></td>
但我不知道如何在視圖中添加路線內的ID。 在我的控制器中,我有一個下面的函數
return Redirect('ReservationDetail?ID='.$reservation->ID);
當我試圖做出這樣的看法時,總是會出錯。
<td><a href= "{{ route("ReservationDetail?ID='.$getData->ID'") }}" >{{ $getData->ID }}</a></td>
UrlGenerator.php第307行中的ErrorException:路由[ReservationDetail?ID ='。3']未定義
您的錯誤是: Route [ReservationDetail?ID='.3'] not defined
表示找不到此路線。
在終端中檢查php artisan route:list
,查看是否存在帶有ReservationDetail
名稱的任何路由。
如果沒有,那么嘗試添加您的web.php
Route::get('/ReservationDetail',ReservationDetailController@get_by_id)->name('ReservationDetail');
在您的ReservationDetailController
嘗試一下:
function get_by_id($ID){
$getData = ReservationDetail::where('ID',$ID)->first();
return view('detail',compact('getData'));
}
在刀片視圖中:
<a href= "{{ route('ReservationDetail', ['ID' => $getData->ID] ) }}">{{ $getData->ID }}</a></td>
使用url()
輔助函數。
<td><a href= "{{ url("ReservationDetail?ID='.$getData->ID'") }}" >{{ $getData->ID }}</a></td>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.