I have set some param In my BaseController:
class BaseController{
public $user;
public $param;
...
__construct(){
$this->user = Auth::user();
$this->param = Input::all();
...
}
}
You know,i could use $this->user to get the user info in every controller. But now,i want to get the user info in UserHandler@update for log.How to get the instance of current controller?like:
class UserHandler{
public function onUpdate()
{
$instance = SomeClass::getCurrent();
$user = $instance->user;
}
}
I don't want to use Auth::user() method.Because that's a complex process.
答案 0 :(得分:0)
通常,所有内容都位于称为应用程序的容器中
$controller = app(\Illuminate\Routing\Route::class)->controller;
还有一种更好的方法
$controller = request()->route()->controller;
在Laravel 7.29.3上测试