Can I have an easier access to the related DB entities than just one textual value of one of the entity's columns?
Currently, I can only output an ID of the related entity, and then manually click on that entities view from the menu and search by the copied ID. It is slow and cumbersome.
orders;order_items;orders, create BREAD with a hasMany relationship with order_items;order_items, create BREAD with a blongsTo relationship with orders;orders and two rows in order_items related to the one orders row;order_items;orders;order_items column to the related order items views?order_items column?Maybe someone finds this useful – it adds links to the (sub-)values of the related table.
You have to copy the relationship.blade.php from vendor/tcg/voyager/resources/views/formfields/relationship.blade.php into resources/assets/views/vendor/voyager/formfields/relationship.blade.php and apply the following patch:
diff --git a/resources/views/vendor/voyager/formfields/relationship.blade.php b/resources/views/vendor/voyager/formfields/relationship.blade.php
index cdb436d..c052cac 100644
--- a/resources/views/vendor/voyager/formfields/relationship.blade.php
+++ b/resources/views/vendor/voyager/formfields/relationship.blade.php
@@ -19,7 +19,10 @@
@endphp
@if(isset($query))
- <p>{{ $query->{$options->label} }}</p>
+ <p><a href="{{route(
+ 'voyager.'.Voyager::model('DataType')->whereName($options->table)->first()->slug.'.show',
+ $query->{$options->key}
+ )}}">{{ $query->{$options->label} }}</a></p>
@else
<p>No results</p>
@endif
@@ -63,6 +66,16 @@
$relationshipData = (isset($data)) ? $data : $dataTypeContent;
$model = app($options->model);
$selected_values = $model::where($options->column, '=', $relationshipData->id)->pluck($options->label)->all();
+
+ $routeName = 'voyager.'.Voyager::model('DataType')->whereName($options->table)->first()->slug.'.show';
+ $items = $model::where($options->column, '=', $relationshipData->id)->get()->reduce(
+ function ($links, $item) use ($options, $routeName) {
+ $links[] = [
+ 'label' => $item->{$options->label},
+ 'url' => route($routeName, $item->id)
+ ];
+ return $links;
+ });
@endphp
@if($view == 'browse')
@@ -80,8 +93,8 @@
<p>No results</p>
@else
<ul>
- @foreach($selected_values as $selected_value)
- <li>{{ $selected_value }}</li>
+ @foreach($items as $item)
+ <li><a href="{{$item['url']}}">{{$item['label']}}</a></li>
@endforeach
</ul>
@endif
@JanisE Should be a hook or a pull request. But needs some improvement. We need to test if we can retrieve the relation in DataType before using it. It trows error if no bread was created for the relation.
Trowed when no BREAD:
Trying to get property 'slug' of non-object (in relationship.blade.php)
Most helpful comment
Maybe someone finds this useful – it adds links to the (sub-)values of the related table.
You have to copy the
relationship.blade.phpfromvendor/tcg/voyager/resources/views/formfields/relationship.blade.phpintoresources/assets/views/vendor/voyager/formfields/relationship.blade.phpand apply the following patch: