leantony / laravel-grid

A grid view for laravel, inspired by the yii2 grid widget
https://leantony.github.io/laravel-grid/
MIT License
91 stars 39 forks source link

View route issue #105

Open Bazinel opened 5 years ago

Bazinel commented 5 years ago

When the filter is applied, the address for the browse button should look like http://site.com/admin/city/edit/10?ref=city-grid but instead it is formed like this http://site.com/admin/city/edit?name=Boston&city=1&ref=city-grid. At this route for removal it is formed correctly irrespective of use of the filter or sorting. Rule in web.php look like this Route::match(['get','post'], '/city/edit/{id}', ['uses' => 'Admin\CityController@edit', 'as' => 'city.edit']);

Bazinel commented 5 years ago

I looked at how routes are formed for viewing and deleting in the file RendersButton.php. For view:

'url' => function ($gridName, $item) {
                return $this->getViewUrl([
                    $gridName => $item->{$this->getDefaultRouteParameter()}, 'ref' => $this->getId()
                ]);
            }

For delete:

 'url' => function ($gridName, $item) {
                return route($this->getDeleteRouteName(), [
                    $gridName => $item->{$this->getDefaultRouteParameter()}, 'ref' => $this->getId()
                ]);
            }

Added this code to configureButtons() method for view button

'url' => function ($gridName, $item) {
                return route($this->getViewRouteName(), [
                    $gridName => $item->{$this->getDefaultRouteParameter()}, 'ref' => $this->getId()
                ]);
            }

The problem was solved, but I do not think that this is the right way.