당신은
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() {
.....
}
}
012을 사용하는 생각이
Route::get('/profile', '[email protected]'); // another route
컨트롤러를 할 수
그런 다음 당신은 위와 동일한 작업을 수행 할 수 있습니다 대신
$test = app('App\Http\Controllers\AdminController')->getshow();// or the other one
사용이
$this->showadmin();
$this->showuser(); // and use If statment ofc
최고 관리자 컨트롤러와 관리 컨트롤러의 주요 차이점은 무엇입니까? 필자는 개인적으로 동일한 컨트롤러로 라우트하고 Auth 논리를 사용하여 컨트롤러의 어떤 메소드를 실행할 것인지 결정합니다. 일반적으로 경로 파일에 논리를 포함하는 것이 가장 좋은 방법은 아닙니다. –
감사합니다. Rob, 그렇게하는 것이 좋지 않다는 것을 이해했습니다. Admin과 SuperAdmin은 내 시스템에서 대시 보드와 기능이 매우 다릅니다. 그래서 컨트롤러와 액션을 2 개로 분리하고 싶습니다. –
여기에 귀하의 답변을 간다 [링크] (http://stackoverflow.com/questions/31368433/single-laravel-route-for-multiple-controllers) –