The GET method is not supported for this route. Supported methods: POST, but it’s POST method. – laravel

  laravel, php

I need help. When I fill in the form and go to the POST method I get an error on the link The GET method is not supported for this route. Supported methods: POST. But i use POST method in form and in route. How do I fix this?

This is my code in index.blade.php

         <button type="button" class="btn btn-info" data-toggle="modal" data-target="#exampleModalCenter">
                                      Add Hotel
                                    </button>
                                    
                                    
                                    <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                      <div class="modal-dialog modal-dialog-centered" role="document">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLongTitle">Add Hotel</h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                          </div>
                                          <div class="modal-body">
                                        <form class="form" action="{{ route('hotel.create.fusr') }}" enctype="multipart/form-data" method="POST" autocomplete="off">
                                            @csrf
                                         <div class="media">
                                                <!-- upload and reset button -->
                                                <div class="media-body mt-75 ml-1">
                                                    <h5>LOGO</h5>
                                                    <div class="form-group">
                                                    <div class="custom-file">
                                                        <input type="file" name="logo" class="custom-file-input" id="customFile" accept="image/*" />
                                                        <label class="custom-file-label" for="customFile">ფაილის არჩევა</label>
                                                    </div>
                                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                                    <br>
                                                    <br>
                                                    <p>allowed JPG, GIF or PNG.</p>    
                                                 </div>
                                                </div>
                                                <!--/ upload and reset button -->
                                            </div>
                                            <br>
                                            <div class="media">
                                                <!-- upload and reset button -->
                                                <div class="media-body mt-75 ml-1">
                                                    <h5>background</h5>
                                                    <div class="form-group">
                                                    <div class="custom-file">
                                                        <input type="file" name="background" class="custom-file-input" id="customFile" accept="image/*" />
                                                        <label class="custom-file-label" for="customFile">ფაილის არჩევა</label>
                                                    </div>
                                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                                    <br>
                                                    <br>
                                                    <p>allowed JPG, GIF or PNG.</p>  
                                                    </div>
                                                </div>
                                                <!--/ upload and reset button -->
                                            </div>
                                        <div class="row">
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="title">სასტუმროს სახელი</label>
                                                    <input type="text" id="title" class="form-control" placeholder="სასტუმროს სახელი" name="name" />
                                                </div>
                                            </div>
                                        </div>                                                
                                            <div class="col">
                                                <div class="form-group">
                                                    <label for="school_creating">Hotel description</label>
                                                    <textarea class="form-control" id="school_creating" placeholder="Write your hotel description" name="description">
                                                                
                                                    </textarea>
                                                </div>
                                            </div>
                                            ...
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="map">Google map</label>
                                                    <textarea type="text" id="map" class="form-control" name="map" placeholder="iframe" /></textarea>
                                                </div>
                                            </div>
                                           </div>
                                          </div>
                                          <div class="modal-footer">
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                            <button type="submit" class="btn btn-primary">Create Hotel</button>
                                          </div>
                                         </form>
                                        </div>
                                      </div>
                                    </div>

This is my code in web.php

      Route::post('user/dashboard/hotels/create', '[email protected]_user')->name('hotel.create.fusr')->middleware(['auth', 'active_user']);

This is my code in HotelsController

   public function create_user(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|unique:hotels|max:255',
            'logo' => 'required',
            'background' => 'required',
            'status' => 'required',
            'address' => 'required|unique:hotels',
            'email' => 'required|unique:hotels|max:255',
            'phone' => 'required|unique:hotels|max:255',
            'price' => 'required|max:255',
            'description' => 'required|min:60',
            'service' => 'required|min:60',
        ]);

        $hotel = new Hotels;
        $hotel->name = $request->name;
        $hotel->description = $request->description;
        $hotel->service_description = $request->service;
        $hotel->slug = str_slug($hotel->name, "-");
        $hotel->status = '2';
        $hotel->address = $request->address;
        $hotel->region = $request->region;
        $hotel->country = $request->country;
        $hotel->preprice = $request->preprice;
        $hotel->price_per_day_person = $request->price;
        $hotel->city_or_state = $request->city;
        $hotel->website = $request->website;
        $hotel->twitter = $request->twitter;
        $hotel->facebook = $request->facebook;
        $hotel->instagram = $request->insta;
        $hotel->email = $request->email;
        $hotel->phone = $request->phone;
        $hotel->phone_two = $request->phone_two;
        $hotel->google_map = $request->map;
        $hotel->owner_id = auth()->user()->id;
        
        if($request->hasFile('logo')){
            $logo = $request->file('logo');
            $filename = time() . '.' . $logo->getClientOriginalExtension();
            Image::make($logo)->save( public_path('/uploads/hotels/' . $filename ) );
        $hotel->logo = $filename;     
        }
        if($request->hasFile('background')){
            $background = $request->file('background');
            $filename = time() . '.' . $background->getClientOriginalExtension();
            Image::make($background)->save( public_path('/uploads/hotels/' . $filename ) );
        $hotel->main_photo = $filename;     
        }
        $hotel->save();

        return redirect()->view('success.hotel');
    }

I really need help. Thank you.

Source: Laravel

Leave a Reply