Laravel-admin: show morphMany Relation in the grid

Created on 21 Nov 2017  ·  3Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: 5.5.21
  • PHP Version:
  • Laravel-admin: 1.5.6

Description:

I'm having a model with a morphMany relation which works well in my controllers.

public function profileImages()
{
    return $this->morphMany('App\Image', 'imaginable');
}

In the grid i'd like to show a badge with a counter $grid->profileImages()->count()->badge(); but the column stays empty. I've also tried to loop over the images via ->display(function ($images) {}) but i'm always getting null as the result.
I couldn't find any code regarding grid and morpMany relationships https://github.com/z-song/laravel-admin/search?utf8=%E2%9C%93&q=morphMany&type= are i'm missing something or is this unsupported at the moment?

Thanks in advance!

Most helpful comment

Try

$grid->model()->with('profileImages');

$grid->column('profile_images')->count()->badge();

All 3 comments

could be related to #946

Try

$grid->model()->with('profileImages');

$grid->column('profile_images')->count()->badge();

@z-song yes that works! Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daguye918 picture daguye918  ·  3Comments

abufalbo picture abufalbo  ·  3Comments

chenyongmin picture chenyongmin  ·  3Comments

MarKco picture MarKco  ·  3Comments

clock1129 picture clock1129  ·  3Comments