November 20, 2016 —John Koster
abort_unless($boolean, $code, $message = '', array $headers)
The abort_unless
helper is the logical opposite of the abort_if
helper function. Like abort
(discussed in the Laravel Application Function: abort article) and abort_if
(discussed in the Laravel Application Helper: abort_if article), the abort_unless
helper function has the potential to abort the executed of the running application.
From the Laravel Application Helper: abort article.
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 argument supplied for $boolean
evaluates to false
, the abort_unless
function will abort execution of the application.
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<?php2 3abort_unless($user->admin, 401);
∎
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.