view src/Generator/View/stubs/index.stub @ 25:1a717c7b211f codex

added support for some basic views
author Luka Sitas <sitas.luka.97@gmail.com>
date Sun, 11 May 2025 21:03:51 -0400
parents
children 555bfaa500ac
line wrap: on
line source

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            All {{ Str::plural(ucfirst('{{ modelVariable }}')) }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
                <div class="flex items-center justify-between mb-4">
                    <span></span>
                    <a href="{{ route('{{ tableName }}.create') }}" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
                        + New {{ ucfirst('{{ modelVariable }}') }}
                    </a>
                </div>
                <table class="w-full text-left border-collapse">
                    <thead>
                        <tr>
                            @foreach($fields as $field)
                                <th class="border-b p-2">{{ ucfirst($field) }}</th>
                            @endforeach
                            <th class="border-b p-2">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($items as $item)
                            <tr>
                                @foreach($fields as $field)
                                    <td class="border-b p-2">{{ $item->$field }}</td>
                                @endforeach
                                <td class="border-b p-2 flex space-x-2">
                                    <a href="{{ route('{{ tableName }}.show', $item) }}" class="text-blue-600 hover:underline">View</a>
                                    <a href="{{ route('{{ tableName }}.edit', $item) }}" class="text-yellow-600 hover:underline">Edit</a>
                                    <form action="{{ route('{{ tableName }}.destroy', $item) }}" method="POST" class="inline">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="text-red-600 hover:underline" onclick="return confirm('Delete?')">Delete</button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td class="p-2" colspan="{{ count($fields)+1 }}">No {{ tableName }} found.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</x-app-layout>