更新时间:2022-03-07 07:14:37
您可以这样做
Route::get('/profile', 'HomeController@profile'); // 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);
}
但是我认为***使用特征
But i think its better to use a trait
trait Show {
public function showadmin() {
.....
}
public function showuser() {
.....
}
}
然后
class HomeController extends Controller {
use Show;
}
然后您可以执行与上述相同的操作,而不是
Then you can do the same as the above but instead of
$test = app('App\Http\Controllers\AdminController')->getshow();// or the other one
使用此
$this->showadmin();
$this->showuser(); // and use If statment ofc