ali_254 Posted June 16, 2021 Share Posted June 16, 2021 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted June 16, 2021 Share Posted June 16, 2021 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? 1 Quote Link to comment Share on other sites More sharing options...
ali_254 Posted June 16, 2021 Author Share Posted June 16, 2021 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted June 16, 2021 Share Posted June 16, 2021 You're going to have to do some troubleshooting. Find out what is causing a GET request against /test2, then we can make it stop doing that. 1 Quote Link to comment Share on other sites More sharing options...
ali_254 Posted June 16, 2021 Author Share Posted June 16, 2021 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted June 17, 2021 Share Posted June 17, 2021 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? 1 Quote Link to comment Share on other sites More sharing options...
Barand Posted June 17, 2021 Share Posted June 17, 2021 7 hours ago, ali_254 said: in route , use post method: ...except when you use get? I am not "laravel literate" but aren't these using "get"? ... 1 Quote Link to comment Share on other sites More sharing options...
ali_254 Posted June 17, 2021 Author Share Posted June 17, 2021 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/ Quote Link to comment Share on other sites More sharing options...
ali_254 Posted June 17, 2021 Author Share Posted June 17, 2021 5 hours ago, Barand said: ...except when you use get? I am not "laravel literate" but aren't these using "get"? ... 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted June 17, 2021 Share Posted June 17, 2021 6 hours ago, ali_254 said: but , when type this address: receive Error http://127.0.0.1:8000/test2/ You cannot browse to /test2 with your address bar. It is only accessible by POSTing an HTML form. 1 Quote Link to comment Share on other sites More sharing options...
Michael-Murage Posted November 12, 2022 Share Posted November 12, 2022 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.