diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 3f7f6367f88f..bf91477e4650 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -207,7 +207,7 @@ public function findOrFail($id, $columns = ['*']) return $result; } - throw (new ModelNotFoundException)->setModel(get_class($this->model)); + throw (new ModelNotFoundException)->setModel(get_class($this->model), $id); } /** diff --git a/src/Illuminate/Database/Eloquent/ModelNotFoundException.php b/src/Illuminate/Database/Eloquent/ModelNotFoundException.php index 102683aa931a..3985636e85d8 100755 --- a/src/Illuminate/Database/Eloquent/ModelNotFoundException.php +++ b/src/Illuminate/Database/Eloquent/ModelNotFoundException.php @@ -14,16 +14,29 @@ class ModelNotFoundException extends RuntimeException protected $model; /** - * Set the affected Eloquent model. + * Ids of the affected instances. * - * @param string $model + * @var int|array + */ + protected $instanceIds; + + /** + * Set the affected Eloquent model and instance ids. + * + * @param string $model + * @param int|array $instanceIds * @return $this */ - public function setModel($model) + public function setModel($model, $instanceIds) { $this->model = $model; + $this->instanceIds = $instanceIds; + + if (is_array($instanceIds)) { + $instanceIds = sprintf('[%s]', implode($instanceIds, ', ')); + } - $this->message = "No query results for model [{$model}]."; + $this->message = "No query results for model [{$model}] with id={$instanceIds}."; return $this; } @@ -37,4 +50,14 @@ public function getModel() { return $this->model; } + + /** + * Get the affected instance ids. + * + * @return int|array + */ + public function getInstanceIds() + { + return $this->instanceIds; + } }