plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Bug]: Helper code couldn't read table field from Eloquent Model

Open funtus00 opened this issue 1 year ago • 1 comments

Bug description

Example.

Using migration:

public function up(): void
{
    Schema::create(with(new User)->getTable(), function (Blueprint $table) {
        $table->timestamps();
        $table->id()->unsigned()->startingValue(10);

        $table->string('first_name')->nullable(false);
        $table->string('last_name')->nullable(false);
        $table->string('email')->unique()->nullable(false);
        $table->enum('status', UserStatus::getValues())->default(UserStatus::New);
        $table->enum('role', UserRole::getValues())->default(UserRole::User);
        $table->string('password')->nullable(false);
        $table->rememberToken();
    });
}

Inside model there is table field: protected $table = 'users';

So migration going correctly, but Laravel Idea showing warning Table not found for App\Models\Common\User\User (users) and can't correctly working with model: for example can't see method User::whereId(int) because plugin doesn't know that this field exist.

How to fix:

Inside migration use name of table like this Schema::create('users', function (Blueprint $table) { or like this private $table_name = 'users'; public function up(): void { Schema::create($this->table_name, function (Blueprint $table) {

Actually this is not big problem, but really wanted to use table name only in 1 place... when you have 700 tables and about 900 migrations this is can be nightmare )

Plugin version

8.1.4.241

Operating system

Windows

Steps to reproduce

No response

Relevant log output

No response

funtus00 avatar May 27 '24 15:05 funtus00

Hello. It should work this way:

(new User())->getTable()

adelf avatar May 31 '24 12:05 adelf