I'd like to present to the user some control depending on whether the current route has a specific middleware or not. In a blade file. Something along the line of:
@if (in_array('auth', Route::getCurrentRoute()->action['middleware']))
show the control
@else
show something else
@endif
When I dd'd the current route, it occurred to me that there are two places to look for the list of middleware applied. In the version 8.0 documentation on the Illuminate\Routing\Route class, there seem to be even more options. Which should I choose?
Thanks @neilstee and @pharaonic for your input! Good to see that I am not the only one in doubt as you both provide contradicting answers.
Looking at the framework code again, it looks like:
middleware(), withoutMiddleware(), and excludedMiddleware() public functions deal with the middleware from the action;
controllerMiddleware() public function deals with the middleware from the controller;
gatherMiddleware() public function deals with middleware from both the action and controller (if applicable) and stores this information in the (public) property computedMiddleware.
That would indicate that gatherMiddleware() is the most reliable source for getting all middleware applied to the route.
The question then rises why the computedMiddleware property is public, as its value might not have been determined yet. But that's a different question.