barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14k stars 1.16k forks source link

Defining database in $table no longer works? #1552

Open Liingon opened 1 month ago

Liingon commented 1 month ago

Versions:

Question:

Before updating to Laravel 11 and ide-helper 3.0.0 I could define a database in the $table field on a Model like protected $table = 'alternate_db.table. Both databases use the same connection.

After the update this no longer generates any documentation that relies on the database table.

Is this intended? Are there any workarounds?

Before 3.0.0:

<?php

namespace App\Models;

use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Example
 *
 * @property int $id
 * @property int $example_int
 * @property string|null $example_string
 *
 * @method static Builder|Example newModelQuery()
 * @method static Builder|Example newQuery()
 * @method static Builder|Example query()
 * @method static Builder|Example whereExampleInt($value)
 * @method static Builder|Example whereExampleString($value)
 * @method static Builder|Example whereId($value)
 *
 * @mixin Eloquent
 */
class Example extends Model {
    protected $table = 'alternate_db.example';

    public $timestamps = false;
}

After 3.0.0:

<?php

namespace App\Models;

use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * @method static Builder|Example newModelQuery()
 * @method static Builder|Example newQuery()
 * @method static Builder|Example query()
 *
 * @mixin Eloquent
 */
class Example extends Model {
    protected $table = 'alternate_db.example';

    public $timestamps = false;
}
Liingon commented 1 month ago

I did another search in issues and found https://github.com/barryvdh/laravel-ide-helper/issues/1487, no idea how I missed that before posting. So this seems to have been reintroduced in the latest release.

hafezdivandari commented 2 weeks ago

Related entry on Laravel 11 upgrade guide: https://laravel.com/docs/11.x/upgrade#deprecated-schema-methods