Laravel No query results for model -
hello i've been using laravel 5 3 days , i'm having problem. testing edit page , getting error no query results model. sample link http://localhost:8000/profile/sorxrob/edit. sorxrob there username. route:
route::bind('user', function($user) { return app\user::where('username', $user)->first(); }); route::get('profile/{user}', 'consultaprofilecontroller@viewprofile'); route::get('profile/{user}/edit', 'consultaprofilecontroller@edit'); and in consultaprofilecontroller here public function:
public function edit($id) { $account = user::findorfail($id); return view('consulta.edit', compact('account')); } whenever try http://localhost:8000/profile/sorxrob/edit gives me error no query results model when change route route::get('profile/{id}/edit', 'consultaprofilecontroller@edit'); works url should http://localhost:8000/profile/6/edit 6 id of sorxob. want username used, don't know problem.
it because have user object.
you have binded user user object. parameter receiving user object, not id. no need query again.
just use
public function edit($user) { return view('consulta.edit', compact('user')); }
Comments
Post a Comment