livewire / livewire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
MIT License
22.39k stars 1.56k forks source link

Allow to change how query string is constructed #576

Closed chrysanthos closed 4 years ago

chrysanthos commented 4 years ago

Is your feature request related to a problem? Please describe. The new query string feature is an awesome addition to the package. I had a couple of projects that I'd like to migrate to Livewire and the "query string automatic update" simplifies a lot of things that I needed to implement on my own in the project I am currently using Livewire.

Until today I was on version 0.5.3 and while trying to update I was looking into altering the behavior of how the query string is constructed (so it matches the previous urls) and remove a lot of code that I had to maintain on my own. It seems like we are unable to change this right now.

In my case I have urls in the form of

?colors=["Blue","White","Pink"]

while Livewire produces something like this

?colors[0]=Blue&colors[1]=White&colors[2]=Pink

Describe the solution you'd like I am proposing either:

  1. Change the way the url is constructed to the first example (or similar). The current implementation creates huge urls and is basically unreadable whereas the first implementation seems to be human and search engine friendly. Additionally the same format is also used by Reactivesearch and other similar packages
  2. Allow the developer to somehow alter it. (However I am not sure how this would be done, seeing how it is currently implemented)
  3. Other possible solution would be to move the related part to the PHP-Side so that the behavior can be easily overridden.

Additional context This is a topic that everyone has its own way of solving so I think the ideal way is to allow the developer to somehow override this.

I created the ticket to receive feedback whether this is something that makes sense and how this can be implemented. If so, I am willing to make a PR for this.

calebporzio commented 4 years ago

Yeah, It would be great to just have the array literals in the query string.

Does this work across the board?

I'd be open to a PR to change this if so.

Also, what about key:value pairs, I'm assuming we'd have to fall back to the current approach?

IP-Developer commented 4 years ago

+1 for this. It would be great to have functionality similar to vue-router, where you can define what kind of query builder to use. This way it'll be a lot more flexible.