Skip to content

Instantly share code, notes, and snippets.

@guiwoda
Created September 8, 2016 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guiwoda/1977d1911698fe8a91dc235db1709cee to your computer and use it in GitHub Desktop.
Save guiwoda/1977d1911698fe8a91dc235db1709cee to your computer and use it in GitHub Desktop.
Wrap a middleware inside another
<?php
class IPDependentMiddleware {
private $wrapped;
public function __construct($wrapped){
$this->wrapped = $wrapped;
}
public function handle($request, $next)
{
if ($request->ip() == '127.0.0.1'){
// lookup in configuration probably
return $next($request);
}
return $this->wrapped->handle($request, $next);
}
}
@guiwoda
Copy link
Author

guiwoda commented Sep 9, 2016

Wrapped could be any other middleware. You could build it like so:

new IPDependentMiddleware(app(ThrottleRequests::class));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment