0

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' => 'rin@test.com', '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
Sanghun Yang
  • 59
  • 1
  • 2
  • 10

2 Answers2

1

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

P. K. Tharindu
  • 2,565
  • 3
  • 17
  • 34
0

just use :

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

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

Zakaria Ab
  • 28
  • 4