简体   繁体   English

如何在视图Laravel 5.2中使用值调用路由?

[英]How to call route with value in view Laravel 5.2?

I have a datatable and I want to go to detail data page when I click the Data ID 我有一个数据表,当我单击“数据ID”时,我想转到详细数据页面

<td><a href= "{{ route('ReservationDetail') }}" >{{ $getData->ID }}</a></td>

But I don't know how to add the ID inside the route in a view. 但我不知道如何在视图中添加路线内的ID。 In my controller I have a function like this below 在我的控制器中,我有一个下面的函数

return Redirect('ReservationDetail?ID='.$reservation->ID);

when I trying to make like that in my view, I always get error. 当我试图做出这样的看法时,总是会出错。

<td><a href= "{{ route("ReservationDetail?ID='.$getData->ID'") }}" >{{ $getData->ID }}</a></td>

ErrorException in UrlGenerator.php line 307: Route [ReservationDetail?ID='.3'] not defined UrlGenerator.php第307行中的ErrorException:路由[ReservationDetail?ID ='。3']未定义

your error is : Route [ReservationDetail?ID='.3'] not defined means it is failed to finding this route. 您的错误是: Route [ReservationDetail?ID='.3'] not defined表示找不到此路线。

check php artisan route:list in your terminal , and see is there any route exists with ReservationDetail name. 在终端中检查php artisan route:list ,查看是否存在带有ReservationDetail名称的任何路由。

if not then try to add in your web.php 如果没有,那么尝试添加您的web.php

Route::get('/ReservationDetail',ReservationDetailController@get_by_id)->name('ReservationDetail');

try this in your ReservationDetailController : 在您的ReservationDetailController尝试一下:

function get_by_id($ID){
     $getData = ReservationDetail::where('ID',$ID)->first();
     return view('detail',compact('getData'));
}

in your blade view : 在刀片视图中:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM