Tim Schmidt
Tim Schmidt

Reputation: 684

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?

Upvotes: 3

Views: 739

Answers (1)

Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41360

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

Upvotes: 2

Related Questions