Last active
March 9, 2019 14:16
-
-
Save driesvints/32fbeee6428e2ed1194d244254b5016c 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::class, | |
], [ | |
// messages | |
]); | |
// With parameters: | |
request()->validate([ | |
'email' => ['required', 'email'], | |
'payment_token' => [ValidPaymentToken::class, $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; | |
{ | |
/** | |
* @var \CreditCardGateway | |
*/ | |
private $gateway; | |
public function __construct(CreditCardGateway $gateway) | |
{ | |
$this->gateway = $gateway; | |
} | |
/** | |
* Determine if the validation rule passes. | |
* | |
* @param string $attribute | |
* @param mixed $value | |
* @return bool | |
*/ | |
public function passes($attribute, $value, array $parameters = []) | |
{ | |
$param1 = $parameters[0]; | |
$param1 = $parameters[0]; | |
// validate stuff; | |
} | |
/** | |
* Get the validation error message. | |
* | |
* @return string | |
*/ | |
public function message() | |
{ | |
return 'custom message'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment