Home > database >  How do I fix The GET method is not supported for this route
How do I fix The GET method is not supported for this route

Time:11-19

Yes, there are a few questions like this and yes I have looked through them! I have been looking at this for a few days now and I'm losing the will to live a little.

I have a mostly working site. I have a page that uses post to add a record to the db, this works. I have another page that adds to a different table using the same method but doesn't work. Bonkers.

On the page that doesn't work:

My form:

<form actio="{{route('site',$site->id)}}/" method="post">
        @csrf

My route:

Route::post('/site/{id}', [SiteController::class, 'store'])->name('site');

My controller:

public function store(){
    $site = new Site ();
    $site->location = request("location");
    $site->rating = request("rating");
    $site->x_coord = request("x_coord");
    $site->y_coord = request("y_coord");
    $site->save();
    return redirect('/location/'.request("location"))->with('mssg','Marker added');
}

The error;

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

I've tried:

things like changing the method to GET, I've even put @method=('POST') in there just in case.

I've seen posts referring to clearing the route using php artisan, the only thing I haven't tried, but how do you do it? I've tried doing it locally in vscode before uploading which didn't work. Do I do this via SSH? I'd have to upgrade my hosting for this so need to be sure.

Thanks

CodePudding user response:

try changing your route to:

Route::any('/site/{id}', [SiteController::class, 'store'])->name('site');

and see how its sending the datas. post the entire form here. there must be an error in that.

CodePudding user response:

We need to add PUT method.

<form actio="{{route('site',$site->id)}}/" method="post">
@csrf

{{ method_field('PUT') }}
== OR ==
<input type="hidden" name="_method" value="PUT">
== OR ==
@method('PUT')

And clear the routing cache.

php artisan route:cache
  • Related