hihet88932's avatar

Create method not found on model

I'm trying to use create on User model but it's saying:

Method 'create' not found in \App\Models\User

User::create([]);

I'm using PHPStorm and Laravel 8, how can I fix that?

Thank you.

0 likes
9 replies
maxxd's avatar

Does your User object extend Model?

1 like
Snapey's avatar

did you create your own user model?

By the way, it should extend Authenticatable

1 like
hihet88932's avatar

@maxxd @snapey It extends Authenticatable and Authenticatable extends Model internally.

@neilstee I tried but it generates a lot of things and I thought there was an alternative, also the only way for me to use create is to generate using the php artisan ide-helper:models.

1 like
Tecktonet's avatar

I discovered that if you reboot Phpstorm, Laravel is discovered by Phpstorm and that error goes away without doing anything extra.

stwilson's avatar

This will be resolved in PHP Storm when you Cmd-Shift-. every time after a migration or model change. It will generate Laravel Idea Helper Code that will help the IDE to understand your Laravel app code.

3 likes
martinbean's avatar

@stwilson I personally just chain ::query after a model name, and then it makes any text editor or IDE with intelligence happy; not just PHPStorm.

- User::create([]);
+ User::query()->create([]);
2 likes

Please or to participate in this conversation.