skip to Main Content

I am attempting to access the route "localhost:8000/contact/edit/{contact}

in my vue file I am attempting it with

<Link :href="route('contact.edit', {contact:contact.id})">Edit Contact</Link>

Route in web.php

    Route::prefix('contact')->group(function() {
        Route::post('/', [ContactController::class, 'store'])->name('contact.store');
        Route::get('/create/{customer}', [ContactController::class, 'create'])->name('contact.create');
        Route::get('/edit/{contact}', [ContactController::class, 'edit'])->name('contact.edit');
    });

Controller:

    public function edit(Contact $contact) {
        dd($contact);
    }

When doing things this way, I get the error that the contact parameter is required:

Error: Ziggy error: 'contact' parameter is required for route 'contact.edit'.

Removing the parameter requirement shows that Ziggy is trying to go here:

GET http://localhost:8000/contact/edit?contact=88

Why would Ziggy default to using a query string on a routine route request? I have overcome this by just writing the url out, but No one on my team can figure out why it is acting this way.

2

Answers


  1. When insert variable after "?"

    Ziggy inserts any undefined parameter in the URL into the URL Query section.

    For example, based on your /contact/edit/{contact} URL, if I asked it for:

    route("contact.edit", { contact: 88, username: "Test" })
    

    this would be the result: /contact/edit/88?username=test, because username was not part of the original URL.

    The error causing Ziggy to put contact in the Query section for you could be that you didn’t update the JS file containing the routes generated by Ziggy after updating Laravel’s web.php file:

    php artisan ziggy:generate.

    When get error: "’xy’ parameter is required"

    When you omit a required parameter from the route() function, Ziggy will throw an error on the console and won’t generate a URL.

    The link provided here is correctly constructed and the route declaration is correct. The issue may have been caused by not updating your website when you added , { contact: contact.id } to the route() function.

    Additionally, if you didn’t manipulate the route() function and are using the latest version, it should work correctly.

    Login or Signup to reply.
  2. So I was working on this problem with OG and we figured out that for some reason the ID is coming out as a string.

    The current solution we have come up with is

    <a :href='route("contact.test",{contact:parseInt(contact.id)})'>Test</a>
    

    The parseInt causes Ziggy to stop throwing a fit. We are going down the path to figure out why our ID is coming out as a string.

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