public findOrFail ( mixed $id, array $columns = ['*'] ) : |
||
$id | mixed | |
$columns | array | |
Résultat |
public function findOrFail($id, $columns = ['*'])
{
$result = $this->find($id, $columns);
if (is_array($id)) {
if (count($result) == count(array_unique($id))) {
return $result;
}
} elseif (!is_null($result)) {
return $result;
}
throw (new ModelNotFoundException())->setModel(get_class($this->model), $id);
}
/** * Find a model by its primary key or throw an exception. * * @param mixed $id * @param array $columns * @return \Illuminate\Database\Eloquent\Model * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function findOrFail($id, $columns = ['*']) { // Try-catch block to have the exception thrown from the repository instead of the model. try { $results = $this->model->findOrFail($id, $columns); $this->reset(); if ($results = $this->hookFindOrFail($results)) { return $results; } } catch (ModelNotFoundException $e) { } throw (new ModelNotFoundException())->setModel(static::$modelClass); }