0
votes

I am trying to edit and update data in laravel but it's throwing an exception MethodNotAllowedHttpException in RouteCollection.php line 219: I have seen other people asking for same issue, but I am not able to understand from their perspective, I am watching tutorials and doing step by step, I have done some research on my own but I am very new to php and framework world so stuck now, here is route code:

Route::get('aboutus', ['as' => 'about', 'uses' => 'PagesController@about']);
Route::get('authors', array('as' => 'authors', 'uses' => 'authors_controller@get_index'));
Route::get('authors/new', array('as' => 'new_author', 'uses' => 'authors_controller@get_new'));
Route::get('authors/{id}', array('as' => 'authorRoute', 'uses' => 'authors_controller@get_view'));
Route::post('authors/authorsWithData', array('as' => 'authorsWithData', 'uses' => 'authors_controller@store'));
Route::get('authors/{id}/edit', array('uses' => 'authors_controller@edit'));
Route::post('authors/{id}/update', array('uses' => 'authors_controller@update'));

controller code:

public function update($id, CreateAuthorRequest $request){
    $author = author::find($id);
    $author->update($request->all());
    return view('authors.view');
}

edit.blade.php code:

        {!! Form::model($author, ['method'=> 'PATCH', 'url' => ['authors/' . 
        $author->id . '/update']]) !!}

    {!! Form::label('name', 'Name:', ['id' => 'labelId']) !!}
    {!! Form::text('name', Input::old('name'), '' 
    , ['id' => 'nameId', 'placeholder' => 'name goes here']) !!}

    <p>
        {!! Form::label('bio', 'Biography:') !!}<br />
        {!! Form::textarea('bio', Input::old('name')) !!}
    </p>    

    <p> {!! Form::submit('Add Author') !!}</p> 

    {!! Form::close() !!}        
2

2 Answers

1
votes

Your route should be accepting a PATCH request, not a POST request.

This is your form:

{!! Form::model($author, ['method'=> 'PATCH', 'url' => ['authors/' . 
    $author->id . '/update']]) !!}

You specified that method is equal to PATCH. So, in your corresponding route, you need to match that:

Old route:

Route::post('authors/{id}/update', array('uses' => 'authors_controller@update'));

New route:

Route::patch('authors/{id}/update', array('uses' => 'authors_controller@update'));
0
votes

Just switch the order of the parameters in the update function.