[英]Laravel 5.4 User Profile NotFoundHttpException
我正在創建一個用戶個人資料,允許他修改他的信息,這里是代碼
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
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');
});
視圖文件夾樹看起來像
view/content/profil.blade.php
view/content/edit.blade.php
問題是定義了路由,但顯示此錯誤消息:
(1/1) NotFoundHttpException
我不知道問題到底在哪里,並在此先感謝
以相同的方式將您的profil.edit
路由更正到/content/{id}/editProfile
和profil.update
。
而且,如果您已命名路由,請嘗試使用route()
輔助函數而不是url()
來生成url,它更通用。
與您的路線( 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.