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

Add model ids to ModelNotFoundForTenantException #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/BelongsToTenants.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function findOrFail($id, $columns = ['*'])
} catch (ModelNotFoundException $e) {
// If it DOES exist, just not for this tenant, throw a nicer exception
if (!is_null(static::allTenants()->find($id, $columns))) {
throw (new ModelNotFoundForTenantException())->setModel(get_called_class());
throw (new ModelNotFoundForTenantException())->setModel(get_called_class(), $id);
}

throw $e;
Expand Down
2 changes: 2 additions & 0 deletions src/Exceptions/ModelNotFoundForTenantException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace HipsterJazzbo\Landlord\Exceptions;

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Arr;

class ModelNotFoundForTenantException extends ModelNotFoundException implements TenantExceptionInterface
{
Expand All @@ -15,6 +16,7 @@ class ModelNotFoundForTenantException extends ModelNotFoundException implements
public function setModel($model, $ids = [])
{
$this->model = $model;
$this->ids = Arr::wrap($ids);
$this->message = "No query results for model [{$model}] when scoped by tenant.";

return $this;
Expand Down