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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -