-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e79822
commit 81626fc
Showing
6 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Kami\Cocktail\Rules; | ||
|
||
use Closure; | ||
use Kami\Cocktail\Models\User; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
|
||
class SubscriberImagesCount implements ValidationRule | ||
{ | ||
public function __construct(private readonly int $maxSubscriberImages, private readonly User $authenticatedUser) | ||
{ | ||
} | ||
|
||
/** | ||
* Run the validation rule. | ||
* | ||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail | ||
*/ | ||
public function validate(string $attribute, mixed $value, Closure $fail): void | ||
{ | ||
if (!config('bar-assistant.enable_billing')) { | ||
return; | ||
} | ||
|
||
if ($value && !is_array($value)) { | ||
$value = [$value]; | ||
} | ||
|
||
$value = (array) $value; | ||
|
||
if (!$this->authenticatedUser->hasActiveSubscription() && (count($value) > $this->maxSubscriberImages)) { | ||
$fail('Total images must be less than ' . $this->maxSubscriberImages); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters