Laravel 5.4用户配置文件NotFoundHttpException

时间:2018-05-18 12:58:59

标签: php laravel-5.4

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

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

我不知道问题的确切位置 提前谢谢

2 个答案:

答案 0 :(得分:0)

以同样的方式更正您的profil.edit路线/content/{id}/editProfileprofil.update

如果您已命名路线尝试使用route()助手而不是url()来生成网址,那么它的清洁程度会更加普遍。

答案 1 :(得分:0)

与您的路线(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');
});