Support the ongoing development of Laravel.io →
IOC Validation
Last updated 1 year ago.
0

I am fairly new to Laravel, but this is a hacky thing which works:

$app =& $this->app
$this->app->validator->resolver(
    function ($translator, $data, $rules, $messages) use(&$app) {
        // Now you have $app
        // How to get an instace of $app here?
        return new RuleAliasExists($translator, $data, $rules, $messages);
    }
);
Last updated 1 year ago.
0

If you are using php 5.4 you can use $this->app in the closure.

$this->app->validator->resolver(
    function ($translator, $data, $rules, $messages) {
        $service = $this->app->make('Service');
        return new RuleAliasExists($translator, $data, $rules, $messages, $service);
    }
);

If running < 5.4 you'll have to use thelastblacks solution.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Schnoop schnoop Joined 27 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.