Newer
Older
FirstLaravel12 / resources / views / todo / index.blade.php
<x-layouts.app :title="__('Todo')">
    @if (session('message.success'))
        <div class="m-4">
            <div class="p-4 bg-cyan-200 text-blue-500 rounded-md text-2xl">
                {{ session('message.success') }}
            </div>
        </div>
    @endif
    <div class="flex h-full w-full flex-1 flex-col gap-4 rounded-xl">

        <div class="mx-4">
            <table class="min-w-full divide-y divide-gray-200">
                <thead>
                    @php
                        $ths = ['ID', 'Task', 'Created At', 'Updated At', 'Delete'];
                    @endphp
                    <tr>
                        @foreach ($ths as $th)
                            <th class="p-1 bg-slate-300">{{ $th }}</th>
                        @endforeach
                    </tr>
                </thead>
                <tbody>
                    @foreach ($todos as $todo)
                        <tr class="{{ $loop->iteration % 2 === 0 ? 'bg-slate-200' : 'bg-white' }}">
                            <td class="p-1 text-center">{{ $todo->id }}</td>
                            <livewire:todo-edit :todo="$todo" />
                            <td class="p-1 text-center">{{ $todo->created_at }}</td>
                            <td class="p-1 text-center">{{ $todo->updated_at }}</td>
                            <td class="p-1 text-center">
                                <form action="{{ route('todo.destroy', $todo) }}" method="POST">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="p-1 bg-red-500 text-white rounded-md"
                                        onclick="return confirm('本当に{{ $todo->id }}番を削除する?');">削除</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        <div class="m-4">
            <form action="{{ route('todo.store') }}" method="POST">
                @csrf
                <div class="flex items-center">
                    <input type="text" name="task" class="w-full p-2 border border-gray-300 rounded-md"
                        placeholder="Add a new task">
                    <button type="submit" class="p-2 ml-2 bg-blue-500 text-white rounded-md">Add</button>
                </div>
            </form>
        </div>

    </div>
</x-layouts.app>