skip to Main Content

I have an error

Missing required parameter for [Route: updatetransaksi] [URI: penjualan/update/{id}] [Missing parameter: id].

web code

route::get('/penjualan/edit/{id_penjualan}', [PenjualanController::class, 'edit']);
route::post('/penjualan/update/{id}', [PenjualanController::class, 'update'])->name('updatetransaksi');

controller code

public function edit(string $id_penjualan)
    {
        $penjualan = Penjualan::where('id_penjualan', $id_penjualan)->first();
        $penjualan = DetailPenjualan::with('Penjualan', 'Barang')->where('id_penjualan', $id_penjualan)->get();
        $penjualanData = Penjualan::with('pembeli', 'detailPenjualan.barang')->find($id_penjualan);
        $pembeli = Pembeli::find($id_penjualan);
        $barang = Barang::all();

        return view('penjualan.edit', compact('penjualan', 'penjualanData', 'pembeli', 'barang', 'id_penjualan'));
    }

public function update(Request $request, $id_penjualan)
    {}

view code

<form action="{{ url('updatetransaksi', ['id' => $id_penjualan]) }}" method="POST">

how to solve this error

2

Answers


  1. Your controller method and route parameter don’t match. You either change your route definition from this:

    route::post('/penjualan/update/{id}', [PenjualanController::class, 'update'])->name('updatetransaksi')
    

    to this:

    route::post('/penjualan/update/{id_penjualan}', [PenjualanController::class, 'update'])->name('updatetransaksi')
    

    or your controller function definition from this:

    public function update(Request $request, $id_penjualan)
    

    to this:

    public function update(Request $request, $id)
    

    Either way works fine.

    Login or Signup to reply.
  2. In Form

    <form action="{{ route('updatetransaksi', ['id' => $id_penjualan]) }}" method="POST">
    

    use route() instead of url(). URL route won’t automatically resolve named routes and their parameters

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search