laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
166 stars 7 forks source link

[Feature Request]: Support for autocompletion in Model attributes `$appends`, `$with`, `$casts`, `$touches`, `$dates`, `$fillable`, `$guarded`, `$withCount` #657

Open ralphjsmit opened 1 year ago

ralphjsmit commented 1 year ago

Feature Description

One of the most useful autocompletions for me is the database column autocompletion on Eloquent models and in factories. One useful aspect where this autocompletion is still missing is in the Eloquent properties at the top of a model.

I think that I have listed most properties below and it would be great if you could add auto-completion for these array properties:

Getters/attributes

Column names

Relations

It would be awesome if you could add support for the autocompletion on these arrays. Thanks!

adelf commented 1 year ago

Hi, Ralph. It already works. Maybe you forgot to generate a helper code?

image
ralphjsmit commented 1 year ago

Hi Adel, thanks for your reply!

Hmm, that's interesting. I always have the helper code generated, so I don't think that's the issue.

For example, see these two screencasts:

https://stream.new/v/zgjkHFsxZxWeRefDqbgBazLPKFIDedhKKZMszs9uNxo https://stream.new/v/176nQB5cZZneFZ7NaXdMmj6l2bo85rHKDR8gwxOKXeI

I'm using PhpStorm 2022.2.3. Probably the same issue that's happening here is also the cause for #656.

ralphjsmit commented 1 year ago

The screencasts are in two different projects. I'm on Laravel Idea 6.0.0.222.

adelf commented 1 year ago

As I see, it works but doesn't complete. Could you try Ctrl-Space in the empty strings there?

ralphjsmit commented 1 year ago

Sure! It says "no suggestions".

Schermafbeelding 2022-10-13 om 12 36 35
adelf commented 1 year ago

Could you share your vendor/_laravel_idea folder?

ralphjsmit commented 1 year ago

@adelf Do you have an email to which I can send a zip-file? My email is rjs@ralphjsmit.com, so you can also mail directly.

adelf commented 1 year ago

I've sent you an email. But you can use adel@laravel-idea.com

ralphjsmit commented 1 year ago

Emailed you!

adelf commented 1 year ago

Hey, Ralph. I just saw that you use your own base Model class. Is it something strange there? )

luilliarcec commented 1 year ago

Hi @adelf, I have the same problem. I explain my case. I am separating the project into modules, for example "Inventory", "Invoicing", "Accounting", etc... where each module can many models. It should be noted that my tables are also separated by modules, so in my models I would have something like "src/Domain/Inventory/Models/Items" in the namespace, and my table would be "invetory_items".

That to give you a bit of context. What I did was create a trait that extracts the module and puts it as a suffix to the table, so as not to be writing the name of the table in all my models.

trait HasCompositeTableName
{
    /**
     * Get the table associated with the model.
     *
     * @return string
     */
    public function getTable(): string
    {
        return $this->table ?? Str::snake(
            Str::pluralStudly(
                Str::betweenFirst(static::class, 'Domain\\', '\\').class_basename($this)
            )
        );
    }
}

Because my table name is "magical", and doesn't follow Laravel's nomenclature either, the plugin isn't discovering my migrations and hence the properties I have.

adelf commented 1 year ago

Yes, Laravel Idea doesn't run PHP code, so the ide-helper package is better here. However, you can use both - ide-helper and Laravel Idea Helper code. It should work ok.

ralphjsmit commented 1 year ago

Hey @adelf, yes that's correct. In most projects I'm using a simple base Eloquent Model that sits 'in-between' the base Eloquent model and the models in the project.

namespace Support\Models;

use Illuminate\Database\Eloquent\Model as EloquentModel;

class Model extends EloquentModel
{
    protected $guarded = [];

    // Any handy functions shared by all models in the project (except User-model).
}
cheesegrits commented 1 year ago

Hi, searched for this issue and landed here.

As of a week or so ago, my Laravel IDEA stopped suggesting for model attributes like $fillable. Worked great for the last year, then just quit working entirely. Nada. "No suggestions".

It has also quit suggesting types for things like $casts. There's some other places it has quit working as well, which I can't remember off the top of my head, I'll edit this comment when I run across them again. It's the $fillable and friends which is a problem atm, as I'm working on importing a bunch of models, and you don't realize how much you rely on this plugin for those until it quits working. :)

I'm on PHPStorm EAP 2022.3 RC2. This plugin has been working fine through the entire current PHPStorm EAP cycle. I have the latest IDEA plugin version (updated about an hour ago).

Nothing unusual about my models, just simple ones that extended Eloquent Model directly, usually created with this plugin.