Skip to content

Set default database connection of a validator #38377

Discussion options

You must be logged in to vote

You may do this by defining a custom validator:

namespace App\Classes;

use Illuminate\Validation\Validator as BaseValidator;

class Validator extends BaseValidator
{
    /**
     * Get the Presence Verifier implementation.
     *
     * @param  string|null  $connection
     * @return \Illuminate\Validation\PresenceVerifierInterface
     *
     * @throws \RuntimeException
     */
    public function getPresenceVerifier($connection = null)
    {
        return tap(parent::getPresenceVerifier($connection), function ($verifier) {
            $verifier->setConnection('sqlite');
        });
    }
}

and use it:

$factory = App::make('validator');
$factory->resolver(function (...$args) {
    return 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hafezdivandari
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant