> For the complete documentation index, see [llms.txt](https://shoaib-1.gitbook.io/sirjuni/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shoaib-1.gitbook.io/sirjuni/middleware/chaining-middleware.md).

# Chaining Middleware

Adding multiple middleware to routes

We can chain the `middleware()` function to add multiple middleware to a route. In the framework, only `Auth` middleware comes prebuilt. To make more middleware we can make use of the `sirJuni\Framework\Middleware\Middleware` class. We can create our own middleware by extending from this base class.&#x20;

When creating a middleware, we have to implement 2 methods in that class, one is `handle()` which would give request to the middleware and the other one is `set_fallback_route($route)` which is used to configure a default fallback route to which a redirect is caused if the Middleware fails to process the request.

To use chaining, we can do as follows

```php
Router::add_route('GET', '/admin', [UserController::class, 'show'])->middleware(Auth::class)->middleware(MDW::class);
```

It routes the request through Auth first and then through MDW.
