-
-
Save adamwathan/18fd93b38f09f6409194b2e29e7ad63c 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($param1, $param2) | |
{ | |
return app()->makeWith(self::class, [$param1, $param2]); | |
} | |
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