Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Instance ids are passed to the ModelNotFoundException #15896

Merged
merged 4 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
31 changes: 27 additions & 4 deletions src/Illuminate/Database/Eloquent/ModelNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -37,4 +50,14 @@ public function getModel()
{
return $this->model;
}

/**
* Get the affected instance ids.
*
* @return int|array
*/
public function getInstanceIds()
{
return $this->instanceIds;
}
}