K4UN6
K4UN6

Reputation: 1

I can't solve "Method Not Allowed Exceptions" in Laravel

The method not allowed exceptions is shown as follow, The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE.

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header card-header-success">
                    <h4>Account Registration Form</h4>
                </div>
                    <form method="POST" action="{{ route('accounts.store')}}" enctype="multipart/form-data" id="commentForm">
                        @csrf
                        <!-- Codes -->
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
```

```Route::get('/', function () {
    return view('home');
});

Route::resource("accounts", "AccountController");
Route::get('/accounts', 'AccountController@create');
Route::post('/accounts', 'AccountController@create');
```

Upvotes: 0

Views: 339

Answers (3)

bartfaber
bartfaber

Reputation: 11

Define routes only once in routes/web.php.

Remove the following lines:

Route::get('/accounts', 'AccountController@create');
Route::post('/accounts', 'AccountController@create');

The resource route definition provides in the accounts.store route if you matched the controller methods to the laravel docs.

Make sure that your AccountController also contains a function called store

Upvotes: 1

Mohammed Aktaa
Mohammed Aktaa

Reputation: 1353

This because you overwrote your routes if you need to run routes below resources you need to give them same name of route like this Route::post('/accounts', 'AccountController@create')->name('accounts.store'); Or if you want to use resources routes you need to put it below of your routes to avoid overwrite its name and urls

Upvotes: 0

mohamed hassan
mohamed hassan

Reputation: 489

Rewrite this route

Route::get('/accounts', 'AccountController@create')->name('accounts.create');
Route::post('/accounts', 'AccountController@store')->name('accounts.store');

not post

Upvotes: 0

Related Questions