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 private function getContainer()
{
throw_if(! $this->container, new \Exception('Cannot query assets without specifying the container.'));
return $this->container instanceof AssetContainer
? $this->container
<?php public function where($column, $operator = null, $value = null)
{
if ($column === 'container') {
throw_if($this->container, new Exception('Only one asset container may be queried.'));
$this->container = $operator;
return $this;
<?php public function group($name, $label, $permissions = null)
{
throw_if($this->pendingGroup, new \Exception('Cannot double nest permission groups'));
if (func_num_args() === 3) {
$this->groups[$name] = $label;
<?php $evaluated = eval(str_replace('<?php', '', $contents));
$expected = ['sites' => $config];
throw_if($evaluated !== $expected, new \Exception('The config could not be written.'));
File::put($path, $contents);
$this->checkLine('Site config file updated.');
<?php return collect($collections)->flatMap(function ($collectionHandle) use ($collections, $user) {
$collection = Collection::findByHandle($collectionHandle);
throw_if(! $collection, new CollectionNotFoundException($collectionHandle));
if (! $user->can('create', [EntryContract::class, $collection])) {
return null;
<?php })->all();
}
throw_if(is_array($value), new MultipleValuesEncounteredException($this));
$label = is_null($value) ? null : array_get($this->config('options'), $value, $value);
<?php protected function abortIfUnpublished($item)
{
throw_if($item->published() === false, new NotFoundHttpException);
}
<?php $fields->validate($this->extraRules($fields));
});
throw_if(Arr::get($values, $form->honeypot()), new SilentFormFailureException);
$submission->uploadFiles();
<?php throw_if(FormSubmitted::dispatch($submission) === false, new SilentFormFailureException);
} catch (ValidationException $e) {
return $this->formFailure($params, $e->errors(), $form->handle());
} catch (SilentFormFailureException $e) {
<?php }
try {
throw_if(UserRegistering::dispatch($user) === false, new SilentFormFailureException);
} catch (ValidationException $e) {
return $this->userRegistrationFailure($e->errors());
} catch (SilentFormFailureException $e) {
<?php $sites = config('statamic.sites.sites');
throw_if(count($sites) > 1, new StatamicProRequiredException('Statamic Pro is required to use multiple sites.'));
return $next($request);
}
<?php protected function bindEntries()
{
Route::bind('entry', function ($handle, $route) {
throw_if(
! ($entry = Entry::find($handle)) || $entry->collection()->id() !== $route->parameter('collection')->id(),
new NotFoundHttpException("Entry [$handle] not found.")
);
return $entry;
});
<?php public function directory($directory = null)
{
throw_if($directory, new \LogicException('Cannot set directory on a child store.'));
return $this->parent->childDirectory($this);
}
<?php return $tree;
}
throw_if(isset($tree[0]['children']), new \Exception('Root page cannot have children'));
return $tree;
}
<?php public function next($currentEntry)
{
throw_if($this->params->has('paginate'), new \Exception('collection:next is not compatible with [paginate] parameter'));
throw_if($this->params->has('offset'), new \Exception('collection:next is not compatible with [offset] parameter'));
throw_if($this->collections->count() > 1, new \Exception('collection:next is not compatible with multiple collections'));