Search

Laravel Application Helper Function: abort

November 20, 2016 —John Koster

abort($code, $message = '', array $headers = [])

The abort function will throw an instance of
Symfony\Component\HttpKernel\Exception\HttpException with the given $code, $message and any $headers supplied. These exceptions can be caught and handled through the application's kernel.

If the $code supplied is 404, the abort function will return an instance of
Symfony\Component\HttpKernel\Exception\NotFoundHttpException using only the user supplied $message.

The following example assumes that some $user object exists with the property admin. The example will check to make sure that the admin property is true. If not, the code will abort with a 401 (unauthorized access) error code.

1<?php
2 
3if (!$user->admin) {
4 abort(401);
5}

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.