Laravel Has undefined contstant App\User from tinker

1.3k views Asked by At

I wished create model call the laravel artisan tinker.

so I try execute php tinker .. but App\User command was occurred error.

I don't know. what should I do?

My development enviroment vagrant php 8.* laravel 8.*

enter image description here enter image description here

>>> $user = App\User::create (['name' => 'rin', 'email' => '[email protected]', 'password' => bcrypt('123456')]);
PHP Error:  Class "App\User" not found in Psy Shell code on line 1
 
>>> App\User::find(1)->articles()->create(['title' => 'First article', 'content' => 'First content']);
PHP Error:  Class "App\User" not found in Psy Shell code on line 1
2

There are 2 answers

0
P. K. Tharindu On BEST ANSWER

In Laravel 8 all models sit inside a Models folder by default.

So you need to replace App\User with App\Models\User.

Docs: https://laravel.com/docs/8.x/structure#the-models-directory

0
Zakaria Ab On

just use :

>>> $user = User::create ...

tinker will instanciate an App\Models\User model for you .