Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Get current Controller (processing the request) in View?

Question:

How to get the "current Controller" in a view, that is "Processing" the Request respectively triggering/calling the View. (Beside passing an instance to the view via parameter)?

Is there some "current global Context" similar to Request that I can get like Controller::instance() or similiar?

like image 464
Tim Schmidt Avatar asked Dec 02 '25 09:12

Tim Schmidt


1 Answers

From 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

like image 129
Yevgeniy Afanasyev Avatar answered Dec 04 '25 23:12

Yevgeniy Afanasyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!