mercredi 7 février 2018

Laravel 5.5 PersonalAccessToken table new column

I ve managed to add a new column into oauth_access_tokens table called callback_url. The problem i ve got is when i am trying to pass callback_url value into createToken function.

public function store(Request $request)
{

    $this->validation->make($request->all(), [
        'name' => 'required|max:255',
        'scopes' => 'array|in:'.implode(',', Passport::scopeIds()),
    ])->validate();

    return $request->user()->createToken(
        $request->name, $request->callback_url, $request->scopes ?: []
    );
}

VUEJS COMPONENT:

store() {
            this.accessToken = null;

            this.form.errors = [];

            axios.post('/user/token', this.form)
                    .then(response => {
                        this.form.name = '';
                        this.form.callback_url = '';
                        this.form.scopes = [];
                        this.form.errors = [];

                        this.tokens.push(response.data.token);

                        this.showAccessToken(response.data.accessToken);
                    })
                    .catch(error => {
                        if (typeof error.response.data === 'object') {
                            this.form.errors = _.flatten(_.toArray(error.response.data));
                        } else {
                            this.form.errors = ['Something went wrong. Please try again.'];
                        }
                    });
        },

It works fine without $request->callback_url but with that extra parameter this is an error i am getting back.

Whoops! Something went wrong!

Type error: Argument 2 passed to Models\User::createToken() must be of the type array, string given, called in UserAccessTokenController.php on line 62
Symfony\Component\Debug\Exception\FatalThrowableError
/vendor/laravel/passport/src/HasApiTokens.php
64
{ "file": "/UserAccessTokenController.php", "line": 62, "function": "createToken", "class": "Models\\User", "type": "->" }
{ "function": "store", "class": "UserAccessTokenController", "type": "->" }

Did anyone had that issue or know how to deal with this problem. Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire