Skip to content

Commit 5b47f11

Browse files
committed
- Added support for admin model collections for displaying
Signed-off-by: Arushad Ahmed <dash-8x@hotmail.com>
1 parent 1739dde commit 5b47f11

5 files changed

Lines changed: 30 additions & 1 deletion

File tree

resources/views/bootstrap-5/table/cell.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
{{ $slot }}
88
@elseif($isAdminModel())
99
{!! $value->admin_link !!}
10+
@elseif($isAdminModelCollection())
11+
{!! $value->implode('admin_link', trans('forms::strings.table_array_separator')) !!}
1012
@else
1113
@if($isStatusEnum())
1214
<x-forms::status :framework="$framework" :color="$value->getColor()" :label="$getEnumLabel()" />

resources/views/bootstrap-5/text-entry.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class="{{ $inlineEntryClass }}"
1616
{{ $slot }}
1717
@elseif($isAdminModel())
1818
{!! $value->admin_link !!}
19+
@elseif($isAdminModelCollection())
20+
{!! $value->implode('admin_link', trans('forms::strings.table_array_separator')) !!}
1921
@else
2022
@if($isStatusEnum())
2123
<x-forms::status :framework="$framework" :color="$value->getColor()" :label="$getEnumLabel()" />

resources/views/material-admin-26/table/cell.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
{{ $slot }}
88
@elseif($isAdminModel())
99
{!! $value->admin_link !!}
10+
@elseif($isAdminModelCollection())
11+
{!! $value->implode('admin_link', trans('forms::strings.table_array_separator')) !!}
1012
@else
1113
@if($isStatusEnum())
1214
<x-forms::status :framework="$framework" :color="$value->getColor()" :label="$getEnumLabel()" />

resources/views/material-admin-26/text-entry.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class="{{ $inlineEntryClass }}"
1616
{{ $slot }}
1717
@elseif($isAdminModel())
1818
{!! $value->admin_link !!}
19+
@elseif($isAdminModelCollection())
20+
{!! $value->implode('admin_link', trans('forms::strings.table_array_separator')) !!}
1921
@else
2022
@if($isStatusEnum())
2123
<x-forms::status :framework="$framework" :color="$value->getColor()" :label="$getEnumLabel()" />

src/Support/FormatsValues.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use BackedEnum;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Collection;
78

89
trait FormatsValues
910
{
@@ -23,7 +24,27 @@ public function isStatusEnum(): bool
2324

2425
public function isAdminModel(): bool
2526
{
26-
return $this->value instanceof Model && method_exists($this->value, 'getAdminLinkAttribute');
27+
return $this->checkIfIsAdminModel($this->value);
28+
}
29+
30+
public function checkIfIsAdminModel(mixed $value): bool
31+
{
32+
return $value instanceof Model && method_exists($value, 'getAdminLinkAttribute');
33+
}
34+
35+
public function isAdminModelCollection(): bool
36+
{
37+
if (! $this->value instanceof Collection) {
38+
return false;
39+
}
40+
41+
foreach ($this->value as $item) {
42+
if (! $this->checkIfIsAdminModel($item)) {
43+
return false;
44+
}
45+
}
46+
47+
return true;
2748
}
2849

2950
public function formatValue()

0 commit comments

Comments
 (0)