{{-- resources/views/components/actions.blade.php --}} @php /** * Expected structure: * [ * [ * 'type' => 'view' | 'edit' | 'delete' | 'custom', * 'text' => 'View', * 'route' => route('something.show', $id), * 'class' => 'btn btn-sm btn-primary', * 'id' => 'view-btn-' . $id, * 'attributes' => ['data-id' => $id, 'data-type' => 'view'], * 'icon' => '', * 'confirm' => true/false (for delete), * ] * ] */ @endphp @foreach($actions as $action) @php $route = $action['route'] ?? '#'; $text = $action['text'] ?? ucfirst($action['type'] ?? 'Action'); $class = $action['class'] ?? ''; $idAttr = $action['id'] ? 'id="' . $action['id'] . '"' : ''; $attrs = ''; if (!empty($action['attributes'])) { foreach ($action['attributes'] as $key => $val) { $attrs .= ' ' . $key . '="' . e($val) . '"'; } } // Optional icon $icon = $action['icon'] ?? ''; @endphp @if($action['type'] === 'delete') {!! $icon !!} {{ $text }} @else {!! $icon !!} {{ $text }} @endif {{-- Separator --}} @if (!$loop->last) | @endif @endforeach