Skip to content

Commit

Permalink
Update role rule from deprecated Rule to ValidationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Wycisk committed Jun 5, 2024
1 parent 4039f1d commit 2d1c3e8
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/Rules/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

namespace Laravel\Jetstream\Rules;

use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Laravel\Jetstream\Jetstream;

class Role implements Rule
class Role implements ValidationRule
{
/**
* Determine if the validation rule passes.
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @return bool
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function passes($attribute, $value)
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return in_array($value, array_keys(Jetstream::$roles));
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return __('The :attribute must be a valid role.');
if(!in_array($value, array_keys(Jetstream::$roles))) {
$fail(__('The :attribute must be a valid role.'));
}
}
}

0 comments on commit 2d1c3e8

Please sign in to comment.