Search code examples
phplaravelcrudtinkerlaravel-8

What are the CRUD Commands that have to be run in Tinker with Laravel 8


When I run the known tinder CRUD Commands in Laravel 8, they aren't working

What I ran was the Create and Find commands

$user = new App\User;
App\User::all();

But they aren't working, I knew that in Laravel 8, the Model file is in this path App\Models\ 'File', and I tried to modify the creating code from $user = new App\User; to $user = new App\Models\User; But also this doesn't work and the error I get is

PHP Fatal error:  Class 'App/Models/User' not found in Psy Shell code on line 1 

So generaty what are the changes to tinker in Laravel 8

Note: I also tried to clear the cache and clear the composer and it didn't solve the problem.


Solution

  • In Laravel 8, you should do it this way:

    $user = new \App\Models\User;
    $users = \App\Models\User::all();
    

    or above the controller class declaration, do

    use App\Models\User;
    

    then in the method, you can do

    $user = new User;
    $users = User::all();