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

Sunpower's avatar

How to fix No query results for model [App\User] settingedit in Laravel 5.6?

working with Laravel 5.6 and mysql. in My application i am going to show for edit current loging user name and email. this is User Model

public function scopeUserr($query)
{
     return $query->where('name',Auth::user()->name);

}

and UserController

public function settingedit()
{
    $users = User::userr()->get();
    return view('users.settingedit')->withUsers($users);
}

and My user data edit link is as following,

<a href="/users/settingedit" class="btn btn-primary">Update User</a>

and route is like this,

Route::get('users/settingedit', [
    'uses' => 'UserController@settingedit',
    'as'=> 'users.settingedit',
  ]);

but when I click Update User link following error is occured,

2/2) NotFoundHttpException

No query results for model [App\User] settingedit

how can fix this problem?

0 likes
10 replies
Talinon's avatar

Just a couple thoughts..

Do you have another conflicting route defined somewhere? Do you have something defined in your RouteServiceProvider?

It seems like you're trying to bind a model somewhere, but it's not immediately clear where according to your code sample

Sunpower's avatar

@talinon I have following route,

Route::get('my-settings', [
    'uses' => 'UserController@setting',
    'as'   => 'users.setting',
 
]);
Talinon's avatar

Well, I'm not exactly sure where that error is coming from.. but why don't you just use this within your controller?

public function settingedit()
{
    $data['user'] = auth()->user();
    return view('users.settingedit')->with($data);
}

There is no need to hit the database with an additional query to get the authenticated user. I'd also suggest against retrieving users by name, as it is quite conceivable to have 2 or more users with the same name.

Sunpower's avatar

I monitor some thing although I remove settingedit function name it is occurred above error here...

Talinon's avatar

Turn on debug mode and paste your entire error stack trace.

Cronix's avatar
Cronix
Best Answer
Level 67
return $query->where('name',Auth::user()->name);

Your scope makes no sense. You already have the current logged in users instance (Auth::user()), so why do you need that to query the database just to get it again?

This also doesn't make sense.

$users = User::userr()->get();
return view('users.settingedit')->withUsers($users);

You're only retrieving a single user (the current user), so why call it $users (plural)? That kind of thing is confusing.

With authentication, you always have access to the current user. It queries it and retrieves it for you automatically on every request, so it's available via auth()->user(), or Auth::user(), etc. There is NO need to requery to retrieve what you already have loaded.

Given that, 1) you don't need to query the user and 2) you don't need to return the user to the view. The current user is already available in the view, so just access it directly in the view with one of those methods.

<input type="text" name="name" value="{{ old('name', auth()->user()->name) }}">

That will populate it with their current user name (upon page load), or the submitted the form and there were validation errors it will populate it with the submitted name.

Please or to participate in this conversation.