mercredi 13 janvier 2016

Laravel - MethodNotAllowedHttpException in RouteCollection.php

I'm working with Laravel 5.2 and get this message:

MethodNotAllowedHttpException in RouteCollection.php at line 219:
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 206

I'm trying to update a user, this is my route list: enter image description here

This is how my routes and controller looks like:

Routes:

Route::get('user/profile/{userid}', 'UserController@show');
Route::get('user/edit/{id}', 'UserController@edit');
Route::post('user/edit/{id}', 'UserController@store');

UserController:

public function update(Request $request, $id)
{
    $user = User::findOrFail($id);

    $this->validate($request, [
        'voornaam' => 'required|max:255',
        'email' => 'required|email|max:255|unique:klanten',
        'achternaam' => 'required|max:255',
        'geboortedatum' => 'required|max:10',
        'niveau' => 'required|max:255',
        'adres' => 'required|max:255',
        'postcode' => 'required|max:6',
        'woonplaats' => 'required|max:255',
        'telefoonnummer' => 'required|max:10'
    ]);

    $input = $request->all();
    $user->fill($input)->save();

    Session::flash('flash_message', 'Gebruiker succesvol gewijzigd!');

    return redirect()->back();
}

public function edit($id)
{
    $user = User::findOrFail($id);
    return view('user.edit', ['user' => $user]);
}

I don't use the html form builder but i read that if you don't use a form builder you can use this line in your form in the view:

 <input name="_method" type="hidden" value="PATCH">



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire