AttributeIlluminate\Routing\Attributes\Controllers\Middleware
#[Middleware]
Applies middleware to the Laravel target element, executing processing logic before the route.
Available since
Laravel 13.0
Targets
classmethod
Parameters
$middlewareClosure|stringMiddleware to be applied.
$only?arrayApply middleware only to certain routes.
$except?arrayExclude middleware application to certain routes.
Practical usage
use Illuminate\Routing\Attributes\Controllers\Middleware;
class UsersController {
#[Middleware('auth', ['admin:read'], ['admin:write'])]
public function index() {
return ['data' => []];
}
}