I'm trying to generate dynamic fields on the basis of a dropdown value. I'm using laravel livewire. But whenever I select the dropdown I'm getting "The GET method is not supported for this route. Supported methods: POST." error. The page on which I want to render this functionality consumes post method(which I defined in web.php file).
After many hit trials what I understood whenever I select the dropdown menu it tries to reload the whole page again but with get method(This may not be the case; I'm just guessing). Because, if I put the same code in a web page which consumes get method then it works perfectly fine!
Please help me in finding the root cause and the solution..
web.php
Route::post('/admin/login', [AdminController::class, 'loginAdmin'])->name("users.admin.login");
exaple.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<title>Example</title>
<h1 class="flex justify-center text-2xl font-medium text-black">Welcome Admin</h1>
@livewireStyles
</head>
<body>
<div class="flex-col justify-center">
<div class="flex justify-center">
<p class="text-xl font-medium text-black pt-6">Add a Child</p>
</div>
</div>
@livewire('counter')
</body>
@livewireScripts
</html>
counter.blade.php
<div class="p-6 max-w-sm mx-auto bg-blue-100 rounded-xl shadow-md flex items-center space-x-4">
<form name="add-super-dist" id="add-super-dist">
@csrf
<div class="flex items-center space-x-4 pt-3 ">
<label>Choose one role: </label>
<select wire:model="message" name="roles" id="roles">
<option value="super-distributor">Super Distributor</option>
<option value="distributor">Distributor</option>
<option value="retailer">Retailer</option>
</select>
</div>
@if($message==='distributor')
<div class="flex items-center space-x-4 pt-3 ">
<label class="text-xs">User Id of Super Distributor: </label>
<input type="text" id="super_dist_id" name="super_dist_id" wire:model="superDistId" class="border-solid border-2 border-black-500 border-opacity-75">
</div>
@elseif($message==='retailer')
<div class="flex items-center space-x-4 pt-3 ">
<label class="text-sm">User Id of Distributor: </label>
<input type="text" id="dist_id" name="dist_id" wire:model="distId" class="border-solid border-2 border-black-500 border-opacity-75">
</div>
@endif
<div class="flex items-center space-x-4 pt-3 ">
<label>User Id: </label>
<input type="text" id="userid" name="userid" required="true" wire:model="userId" class="border-solid border-2 border-black-500 border-opacity-75">
</div>
<div class="flex justify-center pt-3">
<button wire:click.prevent="submit()" type="submit" class="border-solid border-2 border-black-500 border-opacity-100 h-8 w-16 bg-blue-300">Add</button>
</div>
</form>
</div>
Counter.php
<?php
namespace AppHttpLivewire;
use IlluminateHttpRequest as HttpRequest;
use LivewireComponent;
class Counter extends Component
{
public $message;
public $userId;
public $distId;
public $superDistId;
public function submit(HttpRequest $request)
{
dd($request);
}
public function render()
{
return view('livewire.counter');
}
}
Screenshot of the error
question from:
https://stackoverflow.com/questions/65859905/the-get-method-is-not-supported-for-this-route-supported-methods-post-in-a 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…