bimoan
bimoan

Reputation: 189

InvalidArgumentException Route not defined

i have problem with my update ,, when i am click submit on update page,, the error show like this

(1/1) InvalidArgumentException Route [kontak] not defined.

this is my route

    Route::get('kontak','ProductController@index');
Route::get('kontak_create','ProductController@create');
Route::post('kontak','ProductController@store')->name('kontak.store');
Route::get('kontak_edit/{id}','ProductController@edit')->name('kontak_edit');
Route::put('kontak_edit/{id}','ProductController@update')->name('kontak_edit');
Route::delete('kontak','ProductController@destroy')->name('kontak.destroy');

my controller

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


        // menggunakan elequent untuk menyimpan ke database
    $product = Product::where('id',$id)->first();
    $product -> namaproduct = $request->input('namaproduct');
    $product -> descriptionproduct = $request->input('descriptionproduct');
    $product -> currency = $request->input('currency');
    $product -> ukuran = $request->input('ukuran');
    $product -> warna = $request->input('warna');
    $product -> type = $request->input('type');
    $product -> stock = $request->input('stock');
    $product -> harganormal = $request->input('harganormal');
    $product -> hargadiskon = $request->input('hargadiskon');
    $product -> tanggaldibuat = $request->input('tanggaldibuat');

    $product->save();


    return redirect()->route('kontak')->with('alert-success','Data berhasil diubah!');
}

. and this is my edit.blade.php

 @foreach($product as $produk)
        <form action="{{ action('ProductController@update', $produk->id) }}" method="post">
            {{ csrf_field() }}
            {{ method_field('PUT') }}

...................

<div class="form-group">
                <button type="submit" class="btn btn-md btn-primary">Submit</button>
                <button type="reset" class="btn btn-md btn-danger">Cancel</button>
            </div>

when i click submit button on edit page.. yhe error show like above ?? whats wrong with my code ??

Upvotes: 1

Views: 1480

Answers (2)

ysfkaya
ysfkaya

Reputation: 398

You should define a route named kontak

Try this.

Route::get('kontak','ProductController@index')->name('kontak');

Upvotes: 2

Ben Farris
Ben Farris

Reputation: 11

Route::get('kontak_edit/{id}','ProductController@edit')->name('kontak_edit');

Route::put('kontak_edit/{id}','ProductController@update')->name('kontak_edit');

Your name for the Get and Put is the same.

Upvotes: 0

Related Questions