skip to Main Content

It works fine on my local server and computer when I upload it to the online server and whenever I try to update a field like description or sometimes when inserting I get 405 and says that method is not allowed.
I used same method (POST) as in web.php and also in my view.

                        <form action="/updateannouncement" method="post" enctype="multipart/form-data">
                            @csrf
                            <input type="hidden" name="id" value="{{ $announce->id }}">

                                    <div class="form-group">
                                        <label class="col-form-label" for="title"><i class="fa fa-pen"></i> Announcement
                                            Title</label>
                                        <input type="text" name="title" class="form-control" value="{{ $announce->title }}" id="title"
                                            placeholder="Enter ..." required>
                                    </div>
                               

this is web.php


Route::post('/insertannouncement', 'announcementController@insert');
Route::post('/updateannouncement', 'announcementController@update')->middleware('restrict');

I realy want help on this guys!!!

2

Answers


  1. Instead of adding a route name like /updateannouncement use the route name in the form. see in the Laravel doc

    In your case, it should be like this…

    Route::post('/insertannouncement', 'announcementController@insert')->name('announcement.store');
    Route::post('/updateannouncement', 'announcementController@update')->middleware('restrict')->name('announcement.update');
    

    and use in the form

    <form action="{{ route('announcement.store') }}" method="post" enctype="multipart/form-data">
       @csrf
       <input type="hidden" name="id" value="{{ $announce->id }}">
    
       <div class="form-group">
           <label class="col-form-label" for="title"><i class="fa fa-pen"></i> Announcement
               Title</label>
           <input type="text" name="title" class="form-control" value="{{ $announce->title }}" id="title"
               placeholder="Enter ..." required>
       </div>
    </form>
    
    Login or Signup to reply.
  2. run following command :

    php artisan route:clear
    

    or

    php artisan optimize:clear
    

    if it didn’t work, take a look on your middleware

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search