Skip to content

Commit 4e29889

Browse files
committed
allow giving a response to abort
1 parent 4e480de commit 4e29889

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/Illuminate/Foundation/helpers.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
use Illuminate\Container\Container;
77
use Illuminate\Contracts\Bus\Dispatcher;
88
use Illuminate\Contracts\Auth\Access\Gate;
9+
use Illuminate\Contracts\Support\Responsable;
910
use Illuminate\Contracts\Routing\UrlGenerator;
1011
use Illuminate\Foundation\Bus\PendingDispatch;
12+
use Symfony\Component\HttpFoundation\Response;
1113
use Illuminate\Contracts\Debug\ExceptionHandler;
1214
use Illuminate\Contracts\Routing\ResponseFactory;
1315
use Illuminate\Contracts\Auth\Factory as AuthFactory;
1416
use Illuminate\Contracts\View\Factory as ViewFactory;
17+
use Illuminate\Http\Exceptions\HttpResponseException;
1518
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
1619
use Symfony\Component\Debug\Exception\FatalThrowableError;
1720
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
@@ -22,7 +25,7 @@
2225
/**
2326
* Throw an HttpException with the given data.
2427
*
25-
* @param int $code
28+
* @param \Symfony\Component\HttpFoundation\Response|int $code
2629
* @param string $message
2730
* @param array $headers
2831
* @return void
@@ -32,6 +35,12 @@
3235
*/
3336
function abort($code, $message = '', array $headers = [])
3437
{
38+
if ($code instanceof Response) {
39+
throw new HttpResponseException($code);
40+
} elseif ($code instanceof Responsable) {
41+
throw new HttpResponseException($code->toResponse(request()));
42+
}
43+
3544
app()->abort($code, $message, $headers);
3645
}
3746
}

0 commit comments

Comments
 (0)