Skip to content

Commit

Permalink
Merge a977b09 into 24cb378
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafamaklad committed Sep 6, 2017
2 parents 24cb378 + a977b09 commit bd0aa10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Exceptions/GuardDoesNotMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class GuardDoesNotMatch extends InvalidArgumentException
{
public static function create(string $givenGuard, Collection $expectedGuards)
{
$message = new static("The given role or permission should use guard `{$expectedGuards->implode(', ')}` instead of `{$givenGuard}`.");
$expect = $expectedGuards->implode(', ');
$message = new static("The given role or permission should use guard `{$expect}` instead of `{$givenGuard}`.");

if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
}
}
16 changes: 16 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ public static function getModelForGuard(string $guard)
return config("auth.providers.{$guard['provider']}.model");
})->get($guard);
}

/**
* Log Alert Message
* @param string $message
*
* @return string
*/
public static function logAlertMessage(string $message):string
{
if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
}
}
6 changes: 4 additions & 2 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public static function create(array $attributes = [])
{
$attributes['guard_name'] = $attributes['guard_name'] ?? config('auth.defaults.guard');

if (static::getPermissions()->where('name', $attributes['name'])->where('guard_name',
$attributes['guard_name'])->first()) {
if (static::getPermissions()->where('name', $attributes['name'])->where(
'guard_name',
$attributes['guard_name']
)->first()) {
throw PermissionAlreadyExists::create($attributes['name'], $attributes['guard_name']);
}

Expand Down

0 comments on commit bd0aa10

Please sign in to comment.