Skip to content

Commit

Permalink
fix widget relation panel,
Browse files Browse the repository at this point in the history
Now you can pass in name property subrelation path
earlier: 'name'          => 'order_offer',
new: 'name'          => 'order_offer.account',
  • Loading branch information
izica authored Mar 22, 2021
1 parent 168c9d7 commit 1544da6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/resources/views/widgets/relation_panel.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
@php
if(!isset($entry) || $entry->{$widget['name']} === null){
$entry_relation = data_get($entry, $widget['name']);
if(!isset($entry) || $entry_relation === null){
return;
}
if(isset($widget['visible']) && is_callable($widget['visible'])){
if(!$widget['visible']($entry->{$widget['name']})){
if(!$widget['visible']($entry_relation)){
return;
}
}
if(!isset($widget['fields'])){
$widget['fields'] = [];
foreach ($entry->{$widget['name']}->getFillable() as $propertyName){
foreach ($entry_relation->getFillable() as $propertyName){
$widget['fields'][] = [
'label' => $crud->makeLabel($propertyName),
'name' => $propertyName,
Expand All @@ -28,6 +29,8 @@
if (!isset($widget['buttons']) || $widget['buttons'] !== false) {
$widget['buttons'] = true;
}
@endphp

<div class="row">
Expand All @@ -39,16 +42,16 @@
@foreach($widget['fields'] as $field)
@php
if(isset($field['visible']) && is_callable($field['visible'])){
if(!$field['visible']($entry->{$widget['name']}->{$widget['name']})){
if(!$field['visible']($entry_relation)){
continue;
}
}
$value = '';
if(isset($field['closure'])){
$value = $field['closure']($entry->{$widget['name']});
$value = $field['closure']($entry_relation);
}
if(isset($field['name'])){
$value = data_get($entry->{$widget['name']}, $field['name']);
$value = data_get($entry_relation, $field['name']);
}
@endphp
<tr>
Expand All @@ -67,13 +70,13 @@
</td>
<td>
@if ($widget['button_show'] === true)
<a href="{{ backpack_url($widget['backpack_crud'] . "/" . $entry->{$widget['name']}->id . "/show") }}"
<a href="{{ backpack_url($widget['backpack_crud'] . "/" . $entry_relation->id . "/show") }}"
class="btn btn-sm btn-link">
<i class="la la-eye"></i> {{ trans('backpack::crud.preview') }}
</a>
@endif
@if ($widget['button_edit'] === true)
<a href="{{ backpack_url($widget['backpack_crud'] . "/" . $entry->{$widget['name']}->id . "/edit") }}"
<a href="{{ backpack_url($widget['backpack_crud'] . "/" . $entry_relation->id . "/edit") }}"
class="btn btn-sm btn-link">
<i class="la la-edit"></i> {{ trans('backpack::crud.edit') }}
</a>
Expand Down

0 comments on commit 1544da6

Please sign in to comment.