Extender models of the setTable Passport does not work

Asked

Viewed 79 times

1

I extended the 5 models of the Passport:

inserir a descrição da imagem aqui

I extended because I have to add Shema to the table name and for that I have used this function in the constructor of my other models:

public function __construct() {
    parent::__construct();

    $this->setTableName('financial_profile');
}

And extended in the models the GSModel:

class GSModel extends Model
{
    protected $schema;

    public function __construct() {

        parent::__construct();

        $this->schema = config('database.schema');
    }

    public static function boot()
    {
        parent::boot();

        static::addGlobalScope('notExcluded', function (Builder $builder) {
            $builder->where('is_excluded', false)->orWhereNull('is_excluded');
        });
    }

    public $timestamps = false;

    public function setTableName($table) {
        $this->setTable($this->schema.'.'.$table);
    }
}

In the extended models of the Passport tried to do just as in the example:

class OauthAccessTokens extends Token
{
    public function __construct() {
        parent::__construct();

        $schema = config('database.schema');

        $this->setTable($schema.'.oauth_access_tokens');
    }
}

And it even works properly, for example, by giving the php artisan migrate files are created in the correct locations, within the schema.

And when rotating the php artisan passport::install clients clients are generated in the table correctly.

However, when Gero tokens this does not store the access token, refresh token nor the remember token.

But as the class Token, for example, extend the Model class, the same as Gsmodel extends, I believe it should work the same way.

<?php

namespace Laravel\Passport;

use Illuminate\Database\Eloquent\Model;

class Token extends Model

Now if I simply change the models to the following format, everything will work correctly.

class OauthAccessTokens extends Token
{
    protected $table = 'gs_schema.oauth_access_tokens';
}

I need the schema to be informed on .env, and the previous way was working properly until then, some dirt on how I can do this?

Today I have at the config/database.php the code:

/*
|--------------------------------------------------------------------------
| Default Database Schema Name
|--------------------------------------------------------------------------
*/

'schema' => env('DB_SCHEMA', ''),

And in my .env:

DB_SCHEMA=gs_schema
  • Does the Oauthaccesstokens class not have to extend the Gsmodel class instead of Token? I haven’t worked with Passport yet, but if it tests if the class is Token type, then you need to make the Gsmodel class extend Token and Oauthaccesstokens extend from Gsmodel

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.