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 guard name to exceptions #2481

Merged
merged 2 commits into from
Aug 21, 2023
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
11 changes: 8 additions & 3 deletions src/Exceptions/PermissionDoesNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

class PermissionDoesNotExist extends InvalidArgumentException
{
public static function create(string $permissionName, string $guardName = '')
public static function create(string $permissionName, ?string $guardName)
{
return new static("There is no permission named `{$permissionName}` for guard `{$guardName}`.");
}

public static function withId(int $permissionId, string $guardName = '')
/**
* @param int|string $permissionId
* @param string $guardName
* @return static
*/
public static function withId($permissionId, ?string $guardName)
{
return new static("There is no [permission] with id `{$permissionId}` for guard `{$guardName}`.");
return new static("There is no [permission] with ID `{$permissionId}` for guard `{$guardName}`.");
}
}
12 changes: 8 additions & 4 deletions src/Exceptions/RoleDoesNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

class RoleDoesNotExist extends InvalidArgumentException
{
public static function named(string $roleName)
public static function named(string $roleName, ?string $guardName)
{
return new static("There is no role named `{$roleName}`.");
return new static("There is no role named `{$roleName}` for guard `{$guardName}`.");
}

public static function withId(int $roleId)
/**
* @param int|string $roleId
* @return static
*/
public static function withId($roleId, ?string $guardName)
{
return new static("There is no role with id `{$roleId}`.");
return new static("There is no role with ID `{$roleId}` for guard `{$guardName}`.");
}
}
4 changes: 2 additions & 2 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function findByName(string $name, $guardName = null): RoleContract
$role = static::findByParam(['name' => $name, 'guard_name' => $guardName]);

if (! $role) {
throw RoleDoesNotExist::named($name);
throw RoleDoesNotExist::named($name, $guardName);
}

return $role;
Expand All @@ -123,7 +123,7 @@ public static function findById($id, $guardName = null): RoleContract
$role = static::findByParam([(new static())->getKeyName() => $id, 'guard_name' => $guardName]);

if (! $role) {
throw RoleDoesNotExist::withId($id);
throw RoleDoesNotExist::withId($id, $guardName);
}

return $role;
Expand Down