2017-02-27 69 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

仍给我相同的输出 –