0

last night i tried and check several times tried to seek "konsuman" in my route, model, controller, database, and views. but i found nothing. the correct value is "konsumen" but after run in browser show error

ErrorException (E_ERROR)
Missing required parameters for [Route: konsumen.update]
[URI: konsumen/{konsuman}]. (View: D:\xampp\htdocs
\skh\resources\views\konsumen\edit.blade.php).

i check in several times to make sure its "konsumen" not "konsuman" but laravel show error like above.

is there any mistaken in my code or maybe another erorr. enclosed my complete work.

konsuman shows in route list, actualy there is no konsuman. the true value is konsumen

laravel show error because can't find konsuman

here is the link of my complete code in route, model, controller, database and view. thank you for the attention given

5 Answers 5

1

You forgot add param to route('konsumen.update').

It should be route('konsumen.update', ['konsuman' => $id])

$id is the id of konsumen record you're editing.

Sign up to request clarification or add additional context in comments.

Comments

0

You forgot to write required in kde_konsumen

$request->validate([
        'kde_konsumen',
        'nma_konsumen' => 'required',
        'alm_konsumen' => 'required',
        'tlp_konsumen' => 'required',
    ]);

to

$request->validate([
        'kde_konsumen' => 'required',
        'nma_konsumen' => 'required',
        'alm_konsumen' => 'required',
        'tlp_konsumen' => 'required',
    ]);

Comments

0

Try replacing the form action tag value in

edit.blade.php

to <form action="{{ '/konsumen/'. $konsumen->kde_konsumen) }} " method="POST">

2 Comments

thank you for your solution, its worked, but i tried to make the code same among other application. not mix it up. hence for other case your code wis working, but in my case not working.
just like in my description, my code (variable) or other name dont have "konsuman" but laravel display "konsuman" which this cause make the code not working. i have 5 code identically used the code above work fine. only this code error
0

This is one drawback of using resource in laravel route. It does create all the CURD routes, but it has its own standards that you need to follow. So when you have created

 Route::resource('konsumen', 'KonsumenController');

This in turn generated the routes that you can see in your screenshot. Take a look at the update route, it expects a parameter. So whereever you are using konsumen.update route you also need to pass a parameter konsuman. So it would be like this

route('konsumen.update', ['konsuman' => <someValue>])

Just like @PhucLam said

Comments

0

You are missing one thing. In your controller, you are accepting the $konsumen model object. But you didn't define how your $konsumen will convert to the model object. Because from URL you are getting an id.

To solve this you need to do some settings in your RouteServiceProvide class. Below is the code you need to add in your provider:-

public function boot()
{
    Route::model('konsumen', \App\Konsumen::class);

    parent::boot();
}

After this, your code will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.