Php 来自路由器的Laravel 5备用呼叫控制器

Php 来自路由器的Laravel 5备用呼叫控制器,php,laravel-5.6,Php,Laravel 5.6,根据请求参数,我需要显示三个页面。 现在,它在文档中实现: 这就是我的想法,我省略了一些代码 路线: Route::get('/home/{mode}', 'ModeController@show'); 控制器: switch (mode) { case 0 : // gather the data set 1 return View::make("View one", compact('data set1')) case 1 : // gather the d

根据请求参数,我需要显示三个页面。 现在,它在文档中实现:

这就是我的想法,我省略了一些代码

路线:

Route::get('/home/{mode}', 'ModeController@show');
控制器:

switch (mode) {
  case 0 : // gather the data set 1
            return View::make("View one", compact('data set1'))
  case 1 : // gather the data set 2
            return View::make("View two", compact('data set2'))
  case 2 : // gather the data set 3
            return View::make("View three", compact('data set3))
} 
当然,控制器变得又笨又笨。 我想认识到这一点

路线: 1.模态参数分析 2.呼叫控制器,取决于模式

控制器: 收集数据并调用视图


可能吗?

嗯,解决方案如下: 在web.php中

Route::get('data', 'data@show')->name('data.show');

Route::get('/', function (request $request) {


if (isset($request->mode)) {  
    $mode_prm = $request->mode;
} else {
    $mode_prm = 0;
}

switch ($mode_prm) {        
    case 0 :
        return redirect()->route('data.show');
    case 1 :
    //and so on
}))

控制器:

switch (mode) {
  case 0 : // gather the data set 1
            return View::make("View one", compact('data set1'))
  case 1 : // gather the data set 2
            return View::make("View two", compact('data set2'))
  case 2 : // gather the data set 3
            return View::make("View three", compact('data set3))
} 
类数据扩展控制器 { //

}

我不知道这个解决方案是否漂亮,但它是有效的。
希望能对别人有所帮助。

请分享完整的方法,不仅仅是
切换
案例部分。