你可以做到这一点
Route::get('/profile', '[email protected]'); // another route
控制器
public function profile() {
if (Auth::check() && Auth::user()->is_admin) {
$test = app('App\Http\Controllers\AdminController')->getshow();
}
elseif (Auth::check() && Auth::user()->is_superadmin) {
$test = app('App\Http\Controllers\SuperAdminController')->getshow();
// this must not return a view but it will return just the needed data , you can pass parameters like this `->getshow($param1,$param2)`
}
return View('profile')->with('data', $test);
}
但我认为它能够更好地使用特质
trait Show {
public function showadmin() {
.....
}
public function showuser() {
.....
}
}
然后
class HomeController extends Controller {
use Show;
}
然后你就可以做同样作为上述但不是
$test = app('App\Http\Controllers\AdminController')->getshow();// or the other one
使用本
$this->showadmin();
$this->showuser(); // and use If statment ofc
你的超级管理员控制器和管理员控制器之间有一个主要区别吗?我个人会路由到同一个控制器,并使用Auth逻辑来确定控制器上要执行的方法。在您的路线文件中使用逻辑通常不是最佳做法 –
感谢Rob,我知道这样做不是一个好习惯。 Admin和SuperAdmin在我的系统中将有一个非常不同的仪表板和功能。这就是为什么我希望将它们分成两个控制器和操作。 –
这里去你的答案[链接](http://stackoverflow.com/questions/31368433/single-laravel-route-for-multiple-controllers) –