简体   繁体   中英

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

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.

And if you have named routes try to use route() helper instead of url() to generate url's, it's cleaner are more universal.

Compared to your routes ( web.php ) and what you want, this is what your web.php file should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM