2017-02-27 87 views
0

我工作的一個Laravel項目中,我有以下途徑填補:缺少必要的參數異常,而參數是在URL

Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'deliver'], function() { 
    Route::get("{pitch}/play", "[email protected]")->name("deliver.play"); 
    Route::get('/', '[email protected]')->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> 

正如你所看到的,我通過$間距參數的路線,但是在執行時出現以下錯誤彈出:

ErrorException in UrlGenerationException.php line 17: 
Missing required parameters for [Route: deliver.play] [URI: deliver/{pitch}/play]. 

這通常意味着{pitch}參數是不給然而,在瀏覽器的地址欄的參數是有,給我的

http://localhost:8000/deliver/empty-pitch-13/play

完整的URL,這樣怎麼可能爲Laravel到沒有看到傳遞給路由的參數?還是有什麼我失蹤?

謝謝。

編輯:

我忘了補充控制器的路線鏈接。那就是:

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

你在做什麼看起來精美絕倫。如果您看到例外頁面,您是如何看到地址欄中存在參數的網址?你確定它不是另一行,在你的視圖或其他視圖中導致錯誤的地方? – Jonathon

回答

0

試試這個:

<a href="{{ route('deliver.play', ['pitch' => $pitch]) }}"> 

和俯仰PARAMS添加到函數像這樣

Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'deliver'], function() { 
    Route::get("{pitch}/play", "[email protected]", function($pitch){ 
    // 
    })->name("deliver.play"); 
    Route::get('/', '[email protected]')->name('deliver'); 
    }); 
+0

沒有改變任何結果。我也忘記提及問題中使用的方法,也用於許多其他工作的路線。 –

+0

我已經編輯了答案,將音高包含在你的參數中。試試 –

+0

仍給我相同的輸出 –