Skip to content

Instantly share code, notes, and snippets.

@driesvints
Forked from adamwathan/ValidPaymentToken.php
Created May 31, 2017 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save driesvints/ed6b806950773dec231f2ef305ffd1b4 to your computer and use it in GitHub Desktop.
Save driesvints/ed6b806950773dec231f2ef305ffd1b4 to your computer and use it in GitHub Desktop.
<?php
request()->validate([
'email' => ['required', 'email'],
'payment_token' => [ValidPaymentToken::with($param1, $param2)],
], [
// messages
]);
<?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