GET method is not supported for route store-cliente. Supported methods: POST

44 Views Asked by At

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.

1

There are 1 best solutions below

2
CodeWithRonny On

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

{{ route('cliente.store') }}

to

{{ route('cliente.save') }}

change your routes from

Route::post('/store-cliente', [ClienteController::class, 'store'])->name('cliente.store');

to

Route::post('/store-cliente', [ClienteController::class, 'store'])->name('cliente.save');

Solution 2: Route should be like this

Route::resource('client','ClienteController');

and controller have code inside all the function don't change these function

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class ClientController extends Controller
{
    function __construct()
    {
         //
    }
    
    public function index()
    {
        //
    }


    
    public function create()
    {
        //
    }


   
    public function store(Request $request)
    { 
        //
       
    }


   
    public function show(Module_name $module_name)
    {
        //
    }


    
    public function edit(Module_name $module_name)
    {
        //
    }


    
    public function update(Request $request, $id)
    {
        //
    }

    

    
    public function destroy(Module_name $module_name)
    {
        //
    }
}

Here is the controller code example. Do not create different routes.

Use this in your view to change or call routes

{{route('client.index')}}

{{route('client.create')}}
{{route('client.store')}}

{{route('client.edit')}}

{{route('client.update')}}

{{route('client.delete')}}