Skip to content

Instantly share code, notes, and snippets.

@driesvints
Last active March 9, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save driesvints/32fbeee6428e2ed1194d244254b5016c to your computer and use it in GitHub Desktop.
Save driesvints/32fbeee6428e2ed1194d244254b5016c to your computer and use it in GitHub Desktop.
<?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
]);
<?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