Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing route model binding key on query filters #450

Closed
caseydwyer opened this issue Aug 9, 2021 · 2 comments · Fixed by #451
Closed

Missing route model binding key on query filters #450

caseydwyer opened this issue Aug 9, 2021 · 2 comments · Fixed by #451
Assignees
Labels

Comments

@caseydwyer
Copy link

caseydwyer commented Aug 9, 2021

Ziggy version

v1.3.5

Laravel version

v8.53.1

Description

Jumped from v0.8.1, so I realize this might have been a known/intentional breaking change, but I'm seeing unexpected behavior on an index route. Also v possible this is just user-error/not accounting for a change, so please steer me toward docs if I've missed something obvious. Getting the following error on a route that used to work:

"Error: Ziggy error: object passed as 'filter' parameter is missing route model binding key 'undefined'."

On Ziggy v0.8.1, this did what we expected for an index route—we pass any applied filters via a nested filter object which were then "converted" to query parameters (eg, /people?filter[name]=Dwyer). This bit of functionality leans on Spatie's Query Builder, in case that's helpful context. Now we're getting the error above.

TIA for any suggestions/thoughts you all might have!

Ziggy call and context

this.route('admin.people.index', {filter: {name: 'Dwyer'}});

Ziggy configuration

{
    "url": "http://admin.cut.test",
    "port": null,
    "defaults": {},
    "routes": {
        "admin.people.index": {
            "uri": "people",
            "methods": [
                "GET",
                "HEAD"
            ],
            "domain": "admin.cut.test"
        }
    }
}

Route definition

Route::get('/people', 'PersonController@index')->name('people.index');
@bakerkretzmar bakerkretzmar self-assigned this Aug 9, 2021
@bakerkretzmar
Copy link
Collaborator

bakerkretzmar commented Aug 9, 2021

Thanks! Your example should work and I can reproduce this error, we'll look into it and work on a fix.

In the meantime, you can work around it by nesting that whole object under the _query key to tell Ziggy to treat it all as query params:

- this.route('admin.people.index', {filter: {name: 'Dwyer'}});
+ this.route('admin.people.index', { _query: { filter: { name: 'Dwyer' } } });

@caseydwyer
Copy link
Author

Awesome, thanks Jacob! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants