From 8103f1e398aff96ab886bb9df40adeaa4035e84e Mon Sep 17 00:00:00 2001 From: izica Date: Wed, 8 Jul 2020 20:48:30 +0700 Subject: [PATCH] relation table fixes --- .../views/widgets/relation_table.blade.php | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/resources/views/widgets/relation_table.blade.php b/src/resources/views/widgets/relation_table.blade.php index 1a233ad..4d9b424 100644 --- a/src/resources/views/widgets/relation_table.blade.php +++ b/src/resources/views/widgets/relation_table.blade.php @@ -24,12 +24,19 @@ } if(!isset($widget['columns'])){ $widget['columns'] = []; - foreach ($entry->{$widget['name']}->getFillable() as $propertyName){ - $widget['columns'][] = [ - 'label' => $crud->makeLabel($propertyName), - 'name' => $propertyName, - ]; - } + + try { + $model = get_class($entry->{$widget['name']}()->getRelated()); + $model = new $model(); + + $widget['columns'] = []; + foreach ($model->getFillable() as $property){ + $widget['columns'][] = [ + 'label' => $crud->makeLabel($property), + 'name' => $property, + ]; + } + } catch (Exception $e){} } if(!isset($widget['columns']) && !isset($widget['model'])){ $widget['columns'] = []; @@ -49,8 +56,8 @@ > - @foreach($widget['columns'] as $propertyName => $propertyLabel) - {{$propertyLabel}} + @foreach($widget['columns'] as $column) + {{$column['label']}} @endforeach @if($widget['buttons'] === true) {{ trans('backpack::crud.actions') }} @@ -60,9 +67,18 @@ @foreach($entry->{$widget['name']} as $model) - @foreach($widget['columns'] as $propertyName => $propertyLabel) + @foreach($widget['columns'] as $column) + @php + $value = ''; + if(isset($column['closure'])){ + $value = $column['closure']($model); + } + if(isset($column['name'])){ + $value = data_get($model, $column['name']); + } + @endphp - {{data_get($model, $propertyName)}} + {{$value}} @endforeach @if($widget['buttons'] === true) @@ -93,8 +109,8 @@ class="btn btn-sm btn-link" data-button-type="delete"> - @foreach($widget['columns'] as $propertyName => $propertyLabel) - {{$propertyLabel}} + @foreach($widget['columns'] as $column) + {{$column['label']}} @endforeach @if($widget['buttons'] === true) {{ trans('backpack::crud.actions') }}