laravelvuejs3url-routinginertiajsziggy

Ziggy Router Defaulting to Query String


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.


Solution

  • 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.