在我的index.blade.php
中,代码如下:
href="/finance/reports?type=monthly&year={{ $month['year'] }}&month={{ $month['id'] }}"
,在web.php
文件中,路由定义为:
Route::get('/reports', 'ReportsController@index')->name('reports');
如何在index.blade.php中传递参数,使其成为命名路由。
答案 0 :(得分:1)
它已经是一个命名路由。要从路由帮助程序获取带有已附加查询参数的命名路由的URL,请执行以下操作:
route('reports', [
'type' => 'monthly',
'year' => $month['year'],
'month' => $month['id'],
]);
将是:
http://yoursite/finance/reports?type=monthly&year=WhatEverThatIs&month=WhatEverThatWas
我正在假设您的路线,并且您在示例中使用的URI是准确的。
答案 1 :(得分:1)
将路线定义为:
Route::get('/finance/reports/{type}/{year}/{month}')->name('reports');
,然后通过以下方式从刀片模板使用它:
href="{{route('reports', ['type' => 'monthly', 'year' => $month['year'], 'month' => $month['id']])}}"
有关更多信息,请参阅文档:https://laravel.com/docs/5.6/routing#required-parameters
答案 2 :(得分:-1)
将路线定义为:
Route :: get('/ reports / {type} / {year} / {month}','ReportsController @ index');
并通过刀片模板以以下方式使用
href =“ your_project_path / reports / monthly / {{$ month ['year']}} // {{$ month ['id']}}”“