dimanche 23 octobre 2016

Bind doesn't work on User model

I have an interface called TFA and a implementation called GoogleTFA. But everytime that I try to use TFA on my User model I get this error:

Type error: Argument 1 passed to App\Models\User::toggleTFA() must implement interface App\Contracts\TFA, none given

This is my method:

public function toggleTFA(TFA $tfa)
   {
        /**
         * If we're disabling TFA then we reset his secret key.
         */
        if ($this->tfa === true)
            $this->tfa_secret_key = $tfa->getSecretKey();

        $this->tfa = !$this->tfa;
        $this->save();
    }

and this is my bind on AppServiceProvider.php:

public function register()
    {
        /**
         * GoogleTFA as default TFA adapter.
         */
        $this->app->bind('App\Contracts\TFA', 'App\Models\GoogleTFA');
    }

Any idea why I'm having this behaviour?. If I type hint TFA $tfa on any method of my controllers it works but I'm trying to keep my logic on models. Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire