Skip to content

Instantly share code, notes, and snippets.

@adamwathan
Forked from driesvints/ValidPaymentToken.php
Last active September 21, 2017 12:19
Show Gist options
  • Save adamwathan/18fd93b38f09f6409194b2e29e7ad63c to your computer and use it in GitHub Desktop.
Save adamwathan/18fd93b38f09f6409194b2e29e7ad63c 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($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