Reputation: 57
I have set some params In my BaseController:
class BaseController{
public $user;
public $param;
...
__construct(){
$this->user = Auth::user();
$this->param = Input::all();
...
}
}
Now I can 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 in my case.
Upvotes: 1
Views: 1611
Reputation: 41430
Normally, everything sits in a container called the Application
$controller = app(\Illuminate\Routing\Route::class)->controller;
And also, there is a nicer way
$controller = request()->route()->controller;
Tested on Laravel 7.29.3
Upvotes: 1