Ad

How To Fix "The GET Method Is Not Supported For This Route. Supported Methods: POST."

- 1 answer

I'm trying to post images in the database with base_64 code. But I get "The GET method is not supported for this route. Supported methods: POST.". What am I doing wrong?

I already tried to delete the route "Route::get('/image', '[email protected]');".

I also tried to change the route "Route::post('/imagepost', '[email protected]');" to Route::get. But it all seems to fail.

My routes:

Auth::routes();
Route::get('/image', '[email protected]');
Route::post('/imagepost', '[email protected]');
Route::resource('/image', 'ImageController');
Route::get('/image/{id}', '[email protected]');

My store function in the ImageController:

public function store(Request $request)
{
    $image = new Image;
    $file = $request['image'];
    $img = base64_encode($file);
    $image->image = $img;
    Auth::user()->images()->save($image);


    return Redirect('/image');
}

My blade where I upload and post the image:

@if(Auth::check())
    <form id="image" type="POST" name="image" action="/imagepost">
        @csrf
        <input type="file" name="image" />
        <input type="submit" name="submit" />
    </form>
@else

If you need more details, please ask!

I expect the image to be in the database but it actually shows the error message "The GET method is not supported for this route. Supported methods: POST".

Ad

Answer

You have a mistake in your form tag. To set the method, you should use the method attribute, not type:

<form id="image" method="POST" name="image" action="/imagepost">
    @csrf
    <input type="file" name="image" />
    <input type="submit" name="submit" />
</form>
Ad
source: stackoverflow.com
Ad