Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JakeG's avatar
Level 1

The POST method is not supported for this route. Supported methods: GET, HEAD.

I'm trying to save data into my database. The code works before and I think I didn't touch it at all but when I tried to save a data into my database again an error occurs where "The POST method is not supported for this route. Supported methods: GET, HEAD." below is the code of my form

                   <form id="contact" action="{{url('/reservation')}}" method="post" enctype="multipart/form-data">
                    @csrf
                      <div class="row">
                        <div class="col-lg-12">
                            <h4>RiceServation</h4>
                        </div>
                        <div class="col-lg-6 col-sm-12">
                          <fieldset>
                            <input class="form-design" name="name" type="text" id="name" placeholder="Your Name*" required="">
                          </fieldset>
                        </div>
                        <div class="col-lg-6 col-sm-12">
                          <fieldset>
                          <input class="form-design" name="email" type="text" id="email" pattern="[^ @]*@[^ @]*" placeholder="Your Email Address" required="">
                        </fieldset>
                        </div>
                        <div class="col-lg-6 col-sm-12">
                          <fieldset>
                            <input class="form-design" name="phone" type="number" id="phone" placeholder="Phone Number*" required="">
                          </fieldset>
                        </div>
                        <div class="col-md-6 col-sm-12">
                          
                        	<input class="form-design" type="text" name="address" placeholder="Address" required="">

                        </div>
                        <div class="col-lg-6">
                            <div id="filterDate2">    
                              <div class="input-group date" data-date-format="dd/mm/yyyy">
                                <input class="form-design" name="date" id="date" type="text" class="form-control" placeholder="dd/mm/yyyy" required="">
                                <div class="input-group-addon" >
                                  <span class="glyphicon glyphicon-th"></span>
                                </div>
                              </div>
                            </div>   
                        </div>
                        <div class="col-md-6 col-sm-12">
                          
                        	<input class="form-design" type="time" name="time" required="">

                        </div>

    <div class="row col-12">
    @foreach($data as $data)
            <div class="row sm-6 ml-4 mb-1" class="no-gutters" style="height:25px; width: auto;">
                <p class='text-dark mr-2'><input type="checkbox" name="prod_name[]" value="{{$data->title}}"/> {{$data->title}}</p>
                <p class='text-dark'>Qty:</p><input style="width:80px; height:25px;" type="number" name="prod_qty[{{$data->title}}]" min="1" value="1" class="form-control ml-2">
                <input type="hidden" name="product_fee[{{$data->title}}]" value="{{$data->price}}">
                <input type="hidden" name="prod_id[{{$data->title}}]" value="{{$data->id}}">
        </div>
      @endforeach
    </div>
                    <div class=" col-lg-12 mt-5">
                          <fieldset>
                            <button name="submit" type="submit" id="form-submit"  class="main-button-icon">Save Books</button>
                          </fieldset>
                    </div>
                      </div>
    </form>

Below is my route. I'm using get to display my page reservation while post to another controller where I insert my data into database.

    Route::get("/reservation",[HomeController::class,"reservation"]);
    Route::post("/reservation/{id}",[AdminController::class,"reservation"]);

This is the code for my HomeController

               public function reservation(Request $request){
    $user_id=Auth::id();
    $count=cart::where('user_id',$user_id)->count();
    $data=product::all();

    return view('reservation',compact('data','count'));

}

and this is my AdminController

             public function reservation(Request $request)
                {
    if(Auth::id()){
        $user_id=Auth::id();
        $products = '';
        $reserved_qty=0;
        $product_fee=0;
        $prod_id=0;
        $checked_array = $request->input('prod_name', []);
        $quantities = $request->input('prod_qty', []);
        $fees = $request->input('product_fee', []);
        $productid = $request->input('prod_id', []);
        foreach($checked_array as $value){
            $data = new reservation;
            $data->user_id=$user_id;
            $data->name=$request->name;
            $data->email=$request->email;
            $data->phone=$request->phone;
            $data->address=$request->address;
            $data->date=$request->date;
            $data->time=$request->time;

            $data->productz=$request->products="{$value}";
            $data->reserved_qty=$request->$reserved_qty="{$quantities[$value]}";
            $data->product_fee=$request->$product_fee=$fees[$value]*$quantities[$value];
            $data->prod_id=$request->$prod_id=$productid[$value];



            $data->save();

    }
            return redirect()->back();
    }else{
        return redirect('/login');
    }

It works before that's why I didn't make changes to my functions except in route where I added a different route method for another page. That's why I used php artisan route:clear and php artisan route:clear but the problem doesn't seem to be fixed

0 likes
3 replies
Tray2's avatar

Change this line

Route::post("/reservation/{id}",[AdminController::class,"reservation"]);

To

Route::post("/reservation",[AdminController::class,"reservation"]);

Or make sure that you pass the id in your form action

action="{{url('/reservation')}}"

Since you post route expects it.

1 like
JakeG's avatar
Level 1

@Tray2 Thanks for pointing out, I might have removed id in my form action without knowing as it have before.

Tray2's avatar

@JakeG Since it's seems to be the store method and you don't seem to be using the id that you want to pass, you should just remove it from the route.

I also suggest that you use

  • index
  • edit
  • create
  • destroy
  • show
  • store
  • update

as the controller methods instead of giving them names like reservations and instead of AdminController call it ReservationController .

Please or to participate in this conversation.