I'm having the following problem:
The GET method is not supported for route store-cliente. Supported methods: POST.
I'm using laravel 10.
I've already cleaned the cache, route, and even restarted my system.
Apparently I don't see my mistake as being simple and silly.
My route is apparently correct, my form is apparently calling the correct way, and my controller is also correct, and yet it points out the error that I am passing the wrong method.
Could anyone help me with this persistent error.
Route:
Route::get('/index-cliente', [ClienteController::class, 'index'])->name('cliente.index');
Route::get('/create-cliente', [ClienteController::class, 'create'])->name('cliente.create');
Route::post('/store-cliente', [ClienteController::class, 'store'])->name('cliente.store');
Route::get('/show-cliente/{cliente}', [ClienteController::class, 'show'])->name('cliente.show');
Route::get('/edit-cliente/{cliente}', [ClienteController::class, 'edit'])->name('cliente.edit');
Route::put('/update-cliente/{cliente}', [ClienteController::class, 'update'])->name('cliente.update');
Route::delete('/destroy-cliente/{cliente}', [ClienteController::class, 'destroy'])->name('cliente.destroy');
View:
<form action="{{ route('cliente.store') }}" method="POST" class="row g-3">
@csrf
<div class="card mt-4 mb-4 border-light shadow">
<div class="card-header d-flex justify-content-center">
<span>DADOS DO TUTOR</span>
</div>
</div>
<div class="col-md-6 col-sm-6">
<label for="nomeresponsavel1" class="form-label">Nome</label>
<input type="text" name="nomeresponsavel1" class="form-control" id="nomeresponsavel1"
placeholder="Nome Cliente"
value="{{ old('nomeresponsavel1') }}">
</div>
<center>
<div class="col-12">
<button type="submit" class="btn btn-success btn-sm">Cadastrar</button>
</div>
</center>
</form>
Controller:
public function store(ClienteRequest $request)
{
//dd($request);
// Validar o formulário
$request->validated();
try {
// Cadastrar no banco de dados na tabela contas os valores de todos os campos
$cliente = Cliente::create([
'nomeresponsavel1' => $request->nomeresponsavel1,
'nomeresponsavel2' => $request->nomeresponsavel2,
'endereco' => $request->endereco,
'complemento' => $request->complemento,
'telefone' => $request->telefone,
'telefone1' => $request->telefone1,
'nomepet' => $request->nomepet,
'cliente_pacote' => $request->cliente_pacote,
'raca' => $request->raca,
'porte' => $request->porte,
'datanascimento' => $request->datanascimento,
'observacao' => $request->observacao,
'alergia' => $request->alergia,
]);
//dd($request);
// Redirecionar o usuario, enviar a mensagem de sucesso
return redirect()->route('cliente.show', ['cliente' => $cliente->id])->with('success', 'Cliente cadastrada com sucesso');
} catch (Exception $e) {
// Salvar log
Log::warning('Cliente não cadastrada', ['error' => $e->getMessage()]);
// Redirecionar o usuario, enviar a mensagem de erro
return back()->withInput()->with('error', 'Cliente não cadastrada!');
}
}
I'm having the following problem:
The GET method is not supported for route store-cliente. Supported methods: POST.
I'm using laravel 10.
I've already cleaned the cache, route, and even restarted my system.
Apparently I don't see my mistake as being simple and silly.
My route is apparently correct, my form is apparently calling the correct way, and my controller is also correct, and yet it points out the error that I am passing the wrong method.
Could anyone help me with this persistent error.
Laravel uses resources routes and they search dynamically, you do not have to create different routes like index, create, store, edit and update.
Solution 1 change your route from this
to
change your routes from
to
Solution 2: Route should be like this
and controller have code inside all the function don't change these function
Here is the controller code example. Do not create different routes.
Use this in your view to change or call routes