我正在开发一个Laravel项目,我有以下路线:
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'deliver'], function () {
Route::get("{pitch}/play", "DeliverController@play")->name("deliver.play");
Route::get('/', 'DeliverController@index')->name('deliver');
});
名为deliver.play
的路线正如此调用:
<a href="{{ route("deliver.play", $pitch) }}">
<span class="glyphicon glyphicon-picture" data-toggle="tooltip" data-placement="top" title="Go to Playmode"></span>
</a>
如您所见,我将$ pitch参数传递给路径,但是,执行时会弹出以下错误:
ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: deliver.play] [URI: deliver/{pitch}/play].
这通常意味着没有给出{pitch}
param,但是,在我的浏览器的URL栏中,param就在那里,给我完整的URL
http://localhost:8000/deliver/empty-pitch-13/play
那么Laravel怎么可能看不到参数im传递到路线?或者有什么东西我不见了?
感谢。
编辑:
我忘了添加路由链接到的控制器。这是:
public function play(Pitch $pitch)
{
if ($pitch->hasPresentation()) {
$presentation = head($pitch->presentations);
return view("deliver.play.index", $presentation);
}
return redirect()->route('slides.create', $pitch);
}
答案 0 :(得分:0)
试试这个:
<a href="{{ route('deliver.play', ['pitch' => $pitch]) }}">
并将音高参数添加到函数中,如此
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'deliver'], function () {
Route::get("{pitch}/play", "DeliverController@play", function($pitch){
//
})->name("deliver.play");
Route::get('/', 'DeliverController@index')->name('deliver');
});