Skip to content

Commit

Permalink
allow giving a response to abort
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 30, 2018
1 parent 4e480de commit 4e29889
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use Illuminate\Container\Container;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Foundation\Bus\PendingDispatch;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Contracts\Auth\Factory as AuthFactory;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
Expand All @@ -22,7 +25,7 @@
/**
* Throw an HttpException with the given data.
*
* @param int $code
* @param \Symfony\Component\HttpFoundation\Response|int $code
* @param string $message
* @param array $headers
* @return void
Expand All @@ -32,6 +35,12 @@
*/
function abort($code, $message = '', array $headers = [])
{
if ($code instanceof Response) {
throw new HttpResponseException($code);
} elseif ($code instanceof Responsable) {
throw new HttpResponseException($code->toResponse(request()));
}

app()->abort($code, $message, $headers);
}
}
Expand Down

0 comments on commit 4e29889

Please sign in to comment.