Laravel-admin: Relational sorting issue

Created on 7 Aug 2018  路  2Comments  路  Source: z-song/laravel-admin

I have 2 tables: users and activities. Both has the name field.

My grid function of ActivityController looks like this:

protected function grid()
{
    return Admin::grid(Activity::class, function (Grid $grid) {

        $grid->id('ID')->sortable();
        $grid->column('user.username', 'Owner')->sortable();
        $grid->column('name')->sortable();

        $grid->created_at();
        $grid->updated_at();
    });
}

When I sort by name it works fine
image

But when I sort by Owner the name field replaced by name of the Owner
image

Is there anyone has this problem?

Most helpful comment

Problem exists and from here:

https://github.com/z-song/laravel-admin/blob/1320bf488b115b546e5eb0ee9afea7baf4530dce/src/Grid/Model.php#L540

Before this code need add

            $this->queries->push([
                'method'    => 'select',
                'arguments' => [$this->model->getTable() . ".*"],
            ]);

its fix set equal fields from relation to eloquent model.

All 2 comments

Problem exists and from here:

https://github.com/z-song/laravel-admin/blob/1320bf488b115b546e5eb0ee9afea7baf4530dce/src/Grid/Model.php#L540

Before this code need add

            $this->queries->push([
                'method'    => 'select',
                'arguments' => [$this->model->getTable() . ".*"],
            ]);

its fix set equal fields from relation to eloquent model.

pr merged, Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qcol picture qcol  路  3Comments

taimaiduc picture taimaiduc  路  3Comments

amun1303 picture amun1303  路  3Comments

zhenyangze picture zhenyangze  路  3Comments

chenyongmin picture chenyongmin  路  3Comments