Search code examples
phplaravelrouteslaravel-5.3

How to solve MethodNotAllowedHttpException in RouteCollection.php in laravel 5.3?


My view is like this :

{!! Form::open(['route' => ['users.store.year.month', $year, $month]]) !!}                
    @include('users.fields')
{!! Form::close() !!}

My route is like this :

Route::get('users/store/{year}/{month}', 'UserController@store')
        ->name('users.store.year.month');

My controller is like this :

public function store(CreateTunkinRequest $request, $thang, $month)
{
    ...
    return redirect(route('users.proses', ['month' => $month, 'year' => $year]));
}

When I input data and save, there exist error like this :

MethodNotAllowedHttpException in RouteCollection.php line 218:

How can I solve it?


Solution

  • When you are using laravel collective by default, a POST method will be assumed, so change your form to

    {!! Form::open(['route' => ['users.store.year.month', $year, $month] , 'method' => 'get']) !!}

    See https://laravelcollective.com/docs/5.3/html#opening-a-form