skip to Main Content

working with Laravel 9 and this is working fine in my localhost. but when i deploy it with shared hosting on hostgrator and click contact form it is encountered following error messages
SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST.

I have following contact form in the blade file

<div class="content">
@include('partials.alerts')
    <h1 class="heading">Contact Us</h1>
    
    
    <form method="post" action="{{url('form')}}#contact">
        {{method_field('POST')}}
            {{csrf_field()}}
            <div class="form">
  <div class="input-flex">
    <input type="text" name="name" placeholder="Name*" /><br><br>
    <span style="color:red">@error('name'){{$message}}@enderror</span>
    <input type="email" name="email" placeholder="E-mail*" /><br><br>
    <span style="color:red">@error('email'){{$message}}@enderror</span>
    <input type="tel" class="full-width" name="telephone" placeholder="Phone number*" /><br><br>
    <span style="color:red">@error('telephone'){{$message}}@enderror</span>
    <textarea cols="2" rows="2" class="full-width" name="message" placeholder="Message"></textarea>
   </div>
  <button  class="conbtn" type="submit">Submit</button>
</form>

and web.php

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

Route::post('form','AppHttpControllersUserController@store');

Route::get('/user/verify/{token}', 'AppHttpControllersUserController@verifyUser');

how could I fix this problem?

2

Answers


  1. Please try to clear route cache:

    php artisan route:cache
    

    It’s help me

    Login or Signup to reply.
  2. You said you’re using Laravel 9 but the syntax you’re using is in old format.
    Try updating to the following:

    <form method="post" action="{{ url('form') }}#contact">
        @csrf
        <div class="form">
            <div class="input-flex">
                <input type="text" name="name" placeholder="Name*" /><br><br>
                <span style="color:red">@error('name'){{ $message }}@enderror</span>
                <input type="email" name="email" placeholder="E-mail*" /><br><br>
                <span style="color:red">@error('email'){{ $message }}@enderror</span>
                <input type="tel" class="full-width" name="telephone" placeholder="Phone number*" /><br><br>
                <span style="color:red">@error('telephone'){{ $message }}@enderror</span>
                <textarea cols="2" rows="2" class="full-width" name="message" placeholder="Message"></textarea>
            </div>
            <button class="conbtn" type="submit">Submit</button>
        </div>
    </form>
    

    Also update the routes:

    use AppHttpControllersUserController;
    
    Route::post('form', [UserController::class, 'store']);
    Route::get('/user/verify/{token}', [UserController::class, 'verifyUser']);
    

    You may also create a route that runs optimize clear:

    use IlluminateSupportFacadesArtisan;
    
    Route::get('/optimize-clear', function () {
        Artisan::call('optimize:clear');
        return 'Optimize cache cleared';
    });
    

    Let us know if this solves the problem.

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