[英]Laravel 5.4 User Profile NotFoundHttpException
I am creating a user profile that allows him to modify his information here is the code 我正在创建一个用户个人资料,允许他修改他的信息,这里是代码
class ProfilesController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('content.profil');
}
public function editProfile($id)
{
$user = User::find($id);
return view('content.edit', ['user' => $user]);
}
public function updateProfile(Request $request, $id)
{
$user = User::find($id);
$user->name = $request->input('name');
$user->nom = $request->input('nom');
$user->prenom = $request->input('prenom');
$user->adresse = $request->input('adresse');
$user->code_postal = $request->input('code_postal');
$user->ville = $request->input('ville');
$user->pays = $request->input('pays');
$user->num_tele = $request->input('num_tele');
$user->save();
return redirect('/profil');
}
}
Web.php Web.php
Route::group(['middleware' =>'auth'], function(){
Route::get('/profil', 'ProfilesController@index')->name('profil');
Route::get('/content', 'ProfilesController@editProfile')->name('profil.edit');
Route::post('/content', 'ProfilesController@updateProfile')->name('profil.update');
});
the view folder tree looks like 视图文件夹树看起来像
view/content/profil.blade.php
view/content/edit.blade.php
the problem is that the routes are defined but it shows me this error message: 问题是定义了路由,但显示此错误消息:
(1/1) NotFoundHttpException
I don't know where the problem exists exactly and thanks in advance 我不知道问题到底在哪里,并在此先感谢
Correct your profil.edit
route to /content/{id}/editProfile
and profil.update
in the same way. 以相同的方式将您的
profil.edit
路由更正到/content/{id}/editProfile
和profil.update
。
And if you have named routes try to use route()
helper instead of url()
to generate url's, it's cleaner are more universal. 而且,如果您已命名路由,请尝试使用
route()
辅助函数而不是url()
来生成url,它更通用。
Compared to your routes ( web.php
) and what you want, this is what your web.php
file should be 与您的路线(
web.php
)和所需内容相比,这是您的web.php
文件应为
Route::group(['middleware' =>'auth'], function(){
Route::get('/profil', 'ProfilesController@index')->name('profil');
Route::get('/content/{id}/editProfile', 'ProfilesController@editProfile')->name('profil.edit');
Route::post('/content/{id}', 'ProfilesController@updateProfile')->name('profil.update');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.