throw_if

The throw_if function throws the given exception if a given boolean expression evaluates to true:
<?php throw_if(! Auth::user()->isAdmin(), AuthorizationException::class);

throw_if(
    ! Auth::user()->isAdmin(),
    AuthorizationException::class,
    'You are not allowed to access this page.'
);
<?php     function _startUpload($name, $fileInfo, $isMultiple)

    {

        if (FileUploadConfiguration::isUsingS3()) {

            throw_if($isMultiple, S3DoesntSupportMultipleFileUploads::class);



            $file = UploadedFile::fake()->create($fileInfo[0]['name'], $fileInfo[0]['size'] / 1024, $fileInfo[0]['type']);
<?php             'updated*',

        ];



        throw_if(

            str($methodName)->is($protectedMethods),

            new DirectlyCallingLifecycleHooksNotAllowedException($methodName, $this->component->getName())

        );



        $this->callTraitHook('call', ['methodName' => $methodName, 'params' => $params, 'returnEarly' => $returnEarly]);

    }
<?php             }

        }



        throw_if(empty($allRules), new MissingRulesException($this));



        $messages = empty($messages) ? $this->getMessages() : $messages;

        $attributes = empty($attributes) ? $this->getValidationAttributes() : $attributes;
<?php         try {

            return $this->driver->read($path);

        } catch (UnableToReadFile $e) {

            throw_if($this->throwsExceptions(), $e);

        }

    }
<?php                 ? $this->driver->writeStream($path, $contents, $options)

                : $this->driver->write($path, $contents, $options);

        } catch (UnableToWriteFile|UnableToSetVisibility $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php         try {

            $this->driver->setVisibility($path, $this->parseVisibility($visibility));

        } catch (UnableToSetVisibility $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php             try {

                $this->driver->delete($path);

            } catch (UnableToDeleteFile $e) {

                throw_if($this->throwsExceptions(), $e);



                $success = false;

            }
<?php         try {

            $this->driver->copy($from, $to);

        } catch (UnableToCopyFile $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php         try {

            $this->driver->move($from, $to);

        } catch (UnableToMoveFile $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php         try {

            return $this->driver->checksum($path, $options);

        } catch (UnableToProvideChecksum $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php         try {

            return $this->driver->mimeType($path);

        } catch (UnableToRetrieveMetadata $e) {

            throw_if($this->throwsExceptions(), $e);

        }



        return false;
<?php         try {

            return $this->driver->readStream($path);

        } catch (UnableToReadFile $e) {

            throw_if($this->throwsExceptions(), $e);

        }

    }
<?php         try {

            $this->driver->writeStream($path, $resource, $options);

        } catch (UnableToWriteFile|UnableToSetVisibility $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php         try {

            $this->driver->createDirectory($path);

        } catch (UnableToCreateDirectory|UnableToSetVisibility $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }
<?php         try {

            $this->driver->deleteDirectory($directory);

        } catch (UnableToDeleteDirectory $e) {

            throw_if($this->throwsExceptions(), $e);



            return false;

        }