Skip to content

Commit a282511

Browse files
committed
don't fail by supplying a non-existing id via API
1 parent d13847b commit a282511

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

app/Http/Controllers/BaseController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,12 +1877,13 @@ protected function setupSelect2Field($model, string $class, string $field = null
18771877
*/
18781878
protected function select2ViaRequestParam(array $models, BaseModel $model, string $class, string $field, string $placeholder): array
18791879
{
1880-
$model = $models[$class]::findOrFail(request($field));
1880+
$select = [null => $placeholder];
18811881

1882-
return [
1883-
null => $placeholder,
1884-
$model->id => $model->label(),
1885-
];
1882+
if ($model = $models[$class]::find(request($field))) {
1883+
$select[$model->id] = $model->label();
1884+
}
1885+
1886+
return $select;
18861887
}
18871888

18881889
/**

0 commit comments

Comments
 (0)