# Custom Middleware

The Curtain middleware system can be extended to accommodate specific needs. Let's explore how to create and implement custom middleware:

* Creating Custom Middleware:

```php
namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Daycode\Curtain\Facades\Curtain;

class CustomMaintenanceMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        // Let's say you want to allow specific user roles to bypass maintenance
        if (auth()->check() && auth()->user()->hasRole('admin')) {
            return $next($request);
        }

        // Then fall back to default Curtain checks
        if (Curtain::canAccessPath($request)) {
            return $next($request);
        }

        return Curtain::render();
    }
}
```
