Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maidul98's avatar

User::create() results No query results for model [App\User].

I run the following method and for some reason, it makes the table, but then right after it throws an error.

public function create_user(){    
        $user = User::create([
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'email' => $this->email,
            'password' => bcrypt($this->password)
        ]);
}

error:

No query results for model [App\User].

This doesn't make any sense to me; I'm not even looking for results.

Any ideas?

0 likes
8 replies
bobbybouwmann's avatar

Where do you call this method? Do you redirect to a certain route or view after creating this user?

Can you show the code where you call the create_user method?

maidul98's avatar

@BOBBYBOUWMANN -

where create_user() is being called

public function register(){
       try{
           $this->create_user();
           return $this->token();
       }catch(Exception $e){
           return $e->getMessage();
       }
   }
/**
     * return login token
     */
    public function token(){
        $token = $this->user->createToken('login')->accessToken;
        return response()->json(['token' => $token], 200);
    }


In another file, I call this class

 public function register(RegVal $request){
        try{
            $register = new Register($request->first_name, 
            $request->last_name, $request->email, $request->password);
            return $register->register();
        }catch(Exception $e){
            return $e->getMessage();
        }
    }
tykus's avatar

Do you assign the created user (in create_user()?) to $this->user somewhere, I cannot see it??

maidul98's avatar

@TYKUS - Yes, I did. Also i tried running this code in a simple routes file:

Route::get('/test', function () {
    $user = User::create([
        'first_name' => 'Jake',
        'last_name' => 'Paul',
        'email' => '[email protected]',
        'password' => bcrypt('hshshsh')
    ]);
});

And I get the same error No query results for model [App\User].

Super weird

tykus's avatar
tykus
Best Answer
Level 104

Are you trying to query for a User somewhere else as the app is bootstrapping, e.g. in a ServiceProvider, or in a Middleware?

maidul98's avatar

@TYKUS - Hmmm, that has to be it. I'm just not sure where on earth this would be happening. Any ideas on where to look for this query?

tykus's avatar

Laravel Debugbar or Laravel Telescope will tell you where queries are being executed.

Snapey's avatar

No query results for model [App\User]

This error should give you a file, line number and stack trace?

Please or to participate in this conversation.