代码之家  ›  专栏  ›  技术社区  ›  toto01

Laravel 5.4用户配置文件NotFoundHttpException

  •  0
  • toto01  · 技术社区  · 7 年前

    我正在创建一个用户配置文件,允许他修改他的信息这里是代码

    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');
    
        }
    }
    

    网状物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
    

    我不知道问题究竟存在于何处 提前谢谢

    2 回复  |  直到 7 年前
        1
  •  0
  •   Goms    7 年前

    和你的路线相比( web.php )你想要什么,这就是你的 网状物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');
    });
    
        2
  •  0
  •   Daniel    7 年前

    纠正你的错误 profil.edit 通往 /content/{id}/editProfile profil.update 以同样的方式。

    如果你有指定的路线,试着使用 route() 助手而不是 url() 为了生成url,它更干净,更通用。