Angular/Laravel – getting ‘No query results for model [AppModelsUser]’ error

  angular, laravel

I’m working with Laravel and Angular. I want to display the authenticated user’s data. I’m getting datas from Laravel with JSON and I’m using this code for the user datas.

  const headers = new HttpHeaders({
      Authorization: `Bearer ${localStorage.getItem('token')}`
    });
    this.http.get('http://127.0.0.1:8000/api/user', {headers}).subscribe(
      result => (this.user = result,
        
       
    console.log(result))

    );

It’s working but after a certain time this code does not work and I’m getting the error in console.

No query results for model [AppModelsUser]

127.0.0.1:8000/api/user 404 (Not Found)

What am I missing?

UserController

public function user() {
    $user = User::where('id',Auth::id())->firstorfail();
    return response()->json($user);
}

api.php

Route::get('/user', [UserController::class, 'user']);

Source: Laravel

Leave a Reply