-
-
Save driesvints/ed6b806950773dec231f2ef305ffd1b4 to your computer and use it in GitHub Desktop.
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
<?php | |
request()->validate([ | |
'email' => ['required', 'email'], | |
'payment_token' => [ValidPaymentToken::with($param1, $param2)], | |
], [ | |
// messages | |
]); |
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
<?php | |
use Illuminate\Contracts\Validation\Rule; | |
class ValidPaymentToken implements Rule; | |
{ | |
private $gateway; | |
private $param1; | |
private $param2; | |
public function __construct(CreditCardGateway $gateway, $param1, $param2) | |
{ | |
$this->gateway = $gateway; | |
$this->param1 = $param1; | |
$this->param2 = $param2; | |
} | |
public static function with(...$params) | |
{ | |
return app()->makeWith(self::class, ...$params); | |
} | |
public function passes($attribute, $value) | |
{ | |
// validate stuff; | |
} | |
public function message() | |
{ | |
return 'custom message'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment