Профиль пользователя Laravel 5.4 NotFoundHttpException - PullRequest
0 голосов
/ 18 мая 2018

Я создаю профиль пользователя, который позволяет ему изменять свою информацию. Вот код

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 голосов
/ 18 мая 2018

По сравнению с вашими маршрутами (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');
});
0 голосов
/ 18 мая 2018

Корректируйте ваш profil.edit маршрут к /content/{id}/editProfile и profil.update таким же образом.

И если вы назвали маршруты, попробуйте использовать помощник route() вместо url() для генерации URL,это чище, более универсальны.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...