Jump to content

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


ali_254

Recommended Posts

hi...

i want create Validation form in laravel.... when run project , receive this error:

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

 

html form:

<form action="/test2" method="post">
    {{csrf_field()}}
    <input type="text" name="title" id="title">
    <br>
    <input type="text" name="title2" id="title2">
    <br>
    <input type="text" name="title3" id="title3">
    <input type="submit" value="register">
</form>

 

route:

Route::post('/test2', [Homecontroller::class, 'index3']);

 

Homecontroller.php:

  public function index3(Request $request){
        $a=$request->post("title");
       echo $a . "</br>";
        $a2=$request->post("title2");
        echo $a2 . "</br>";
        $a3=$request->post("title3");
        echo $a3 . "</br>";
        $validated = $request->validate([
            'title' => 'required',
            'title2' => 'required',
        ]);





        return view('test2');
    }

 

 

please guide me.thanks

Link to comment
Share on other sites

Apparently something is trying to hit /test2 using GET instead of POST. Is it from the form? Is there any kind of Javascript involved? Does the form you posted, which clearly states it does use POST, actually have anything to do with the issue?

  • Like 1
Link to comment
Share on other sites

1 hour ago, requinix said:

Apparently something is trying to hit /test2 using GET instead of POST. Is it from the form? Is there any kind of Javascript involved? Does the form you posted, which clearly states it does use POST, actually have anything to do with the issue?

i active Authentication system(Login) in my project...

Is there a relationship between this error and the login system?

i dont use from javascript in my project...

Is my code system for designing validation correct?

Link to comment
Share on other sites

in view file , i use post method:

<form action="/test2" method="post">
    {{csrf_field()}}
    <input type="text" name="title" id="title">
    <br>
    <input type="text" name="title2" id="title2">
    <br>
    <input type="text" name="title3" id="title3">
    <input type="submit" value="register">
</form>

 

in route , use post method:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Homecontroller;

Route::get('/test', [Homecontroller::class, 'index2']);

Route::post('/test2', [Homecontroller::class, 'index3']);


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

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

 

controller file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Company;
use App\Models\Customer;
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('home');
    }

    public function index3(Request $request){
        $a=$request->post("title");
       echo $a . "</br>";
        $a2=$request->post("title2");
        echo $a2 . "</br>";
        $a3=$request->post("title3");
        echo $a3 . "</br>";
        $validated = $request->validate([
            'title' => 'required',
            'title2' => 'required',
        ]);





        return view('test2');
    }

    public function index2()
    {
        $data1 = Company::all();
        //    dd($data1->customers);

        //   return view('test',compact('companies'));

        foreach ($data1 as $row) {
            foreach ($row->customers as $row1) {
                echo $row->name . "__________  ";
                echo $row->created_at . "__________  ";
                echo $row->address . "__________  ";
                echo $row->title . "__________  ";
                echo $row->test . "__________  ";
                echo $row1->id . "<br>";
            }
        }
    }


}

 

i dont use get method in MVC

Link to comment
Share on other sites

11 hours ago, requinix said:

But something is trying to use GET. You do not support it, which is why there is an error, but something is trying.

The error message. How did you get it to happen? What did you do to see it?

i use from login system in laravel , so , when login to system , redirect to "home page":

http://127.0.0.1:8000/home

 

when in taskbar type this address , program work with success.

http://127.0.0.1:8000/test

 

but , when type this address: receive Error

http://127.0.0.1:8000/test2/

 

Link to comment
Share on other sites

5 hours ago, Barand said:

...except when you use get? I am not "laravel literate" but aren't these using "get"? ...

image.png.8dc0843813661c470a81553c1ae21ce5.png

 

in method action in form , i use post methode , so , for Received method in route or controller , i use post method , Just like PHP,it's true?

Link to comment
Share on other sites

  • 1 year later...

Its more or less a general error with varying reasons. In my case it was a misspelling of the import inside the controllers

use App\Models\allocation;

// instead of

use App\Models\Allocation;

So lets just say the slightest of errors/mistakes would cause the post request to default to a get request and then throw an error because of it.

Not sure how much sense I'm making here

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.