Skip to content

Commit

Permalink
Updated to support Laravel 9, the package now utilizes the deprecated…
Browse files Browse the repository at this point in the history
… InvokableRule interface instead of the new one introduced in Laravel 10. Future updates will accommodate the removal of Laravel 9 support.
  • Loading branch information
amjadbanimattar committed May 1, 2024
1 parent b46b3cc commit 4f7a959
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/Translatable/Validation/Rules/TranslatableExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Astrotomic\Translatable\Validation\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Contracts\Validation\InvokableRule;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
Expand All @@ -14,8 +14,11 @@
* Custom exists validation for translatable attributes
*
* @author Amjad BaniMattar <[email protected]>
*
* @TODO should be updated to use use Illuminate\Contracts\Validation\ValidationRule; when this package drop of Laravel 9 support
* instead using detracted interface InvokableRule
*/
class TranslatableExists implements ValidationRule
class TranslatableExists implements InvokableRule
{
/**
* The ID that should be ignored.
Expand Down Expand Up @@ -102,4 +105,16 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}
}
}

/**
* Laravel 9 compatibility (InvokableRule interface)
*
* @param string $attribute
* @param mixed $value
* @param Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function __invoke($attribute, $value, $fail): void
{
$this->validate($attribute, $value, $fail);
}
}
19 changes: 17 additions & 2 deletions src/Translatable/Validation/Rules/TranslatableUnique.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
namespace Astrotomic\Translatable\Validation\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Contracts\Validation\InvokableRule;

/**
* Custom unique validation for translatable attributes
*
* @TODO should be updated to use use Illuminate\Contracts\Validation\ValidationRule; when this package drop of Laravel 9 support
* instead using detracted interface InvokableRule
*
* @author Amjad BaniMattar <[email protected]>
*/
class TranslatableUnique extends TranslatableExists implements ValidationRule
class TranslatableUnique extends TranslatableExists implements InvokableRule
{
/**
* Validate if the given attribute is unique.
Expand All @@ -33,4 +36,16 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}
}
}

/**
* Laravel 9 compatibility (InvokableRule interface)
*
* @param string $attribute
* @param mixed $value
* @param Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function __invoke($attribute, $value, $fail): void
{
$this->validate($attribute, $value, $fail);
}
}

0 comments on commit 4f7a959

Please sign in to comment.