dpi74187
2018-07-13 17:27
浏览 74
已采纳

路由web.php文件中的Laravel访问路由参数

The parameter is posted to some_name like this: {{ route('some_name', $id = '1'}} How can I access it in the if condition?

Route::group(['prefix' => '/'], function()
{
    if ( condition )
    {
        Route::get('/route/{id}', 'ControllerA@methodA')->name('some_name');
    } else{
        Route::get('/route{id}', 'ControllerB@methodB')->name('some_name');;
    }
});

How can I use the {id} parameter in the if (condition)? I tried

Route::group(['prefix' => '/'], function($id)
    {
        if ( $id == 1)

And it's not working.

图片转代码服务由CSDN问答提供 功能建议

参数发布到 some_name </ code>,如下所示: {{route ('some_name',$ id ='1'}} </ code> 如何在if条件下访问它?</ p>

  Route :: group(['prefix]  '=&gt;'/'],function()
 {
 if(condition)
 {
 Route :: get('/ route / {id}','ControllerA @ methodA') - &gt; name  ('some_name'); 
} else {
 Route :: get('/ route {id}','ControllerB @ methodB') - &gt; name('some_name');; 
} 
})  ; 
 </ code> </ pre> 
 
 

如何在 if(condition)</ code>中使用 {id} </ code>参数? I 试过</ p>

  Route :: group(['prefix'=&gt;'/'],function($ id)
 {
 if if($ id == 1)  
 </ code> </ pre> 
 
 

它不起作用。</ p> </ div>

3条回答 默认 最新

相关推荐 更多相似问题