【发布时间】:2015-06-10 15:08:11
【问题描述】:
您好,我已经使用 Laravel 5 3 天了,但遇到了问题。我正在测试我的编辑页面,我收到错误No query results for model。这是示例链接http://localhost:8000/profile/sorxrob/edit。 sorxrob 有一个用户名。这是我的路线:
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');
在我的ConsultaProfileController 中,这里是公共函数:
public function edit($id)
{
$account = User::findOrFail($id);
return view('consulta.edit', compact('account'));
}
每当我尝试http://localhost:8000/profile/sorxrob/edit 时,它都会给我错误No query results for model,但是当我将路由更改为Route::get('profile/{id}/edit', 'ConsultaProfileController@edit'); 时,它可以工作,但现在URL 应该是http://localhost:8000/profile/6/edit,其中6 是sorxob 的ID。我想使用用户名,但我不知道问题出在哪里。
【问题讨论】: