#2 create post

This commit is contained in:
Saufi
2026-05-12 10:42:23 +08:00
parent 53be5221e9
commit 0192769ba3
43 changed files with 3331 additions and 26 deletions

View File

@@ -0,0 +1,63 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Create Post') }}
</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">
<div class="p-6 text-gray-900">
<form method="POST" action="{{ route('post.store') }}" class="space-y-6 max-w-2xl">
@csrf
<div>
<x-input-label for="title" :value="__('Title')" />
<x-text-input id="title" class="mt-1 block w-full" type="text" name="title" :value="old('title')" required autofocus autocomplete="off" />
<x-input-error class="mt-2" :messages="$errors->get('title')" />
</div>
<div>
<x-input-label for="slug" :value="__('Slug')" />
<x-text-input id="slug" class="mt-1 block w-full font-mono" type="text" name="slug" :value="old('slug')" required autocomplete="off" placeholder="my-post-slug" />
<x-input-error class="mt-2" :messages="$errors->get('slug')" />
</div>
<div>
<x-input-label for="content" :value="__('Content')" />
<textarea
id="content"
name="content"
rows="10"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>{{ old('content') }}</textarea>
<x-input-error class="mt-2" :messages="$errors->get('content')" />
</div>
<div>
<x-input-label for="status" :value="__('Status')" />
<select id="status" name="status" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
@foreach (\App\Enums\PostStatus::cases() as $status)
<option value="{{ $status->value }}" @selected(old('status', 'draft') === $status->value)>
{{ $status->label() }}
</option>
@endforeach
</select>
<x-input-error class="mt-2" :messages="$errors->get('status')" />
</div>
<div class="flex items-center gap-4">
<x-primary-button>{{ __('Save') }}</x-primary-button>
<a href="{{ route('post.index') }}" class="text-sm text-gray-600 underline hover:text-gray-900">
{{ __('Cancel') }}
</a>
</div>
</form>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,70 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Edit Post') }}
</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">
<div class="p-6 text-gray-900">
@if (session('status') === 'post-updated')
<div class="mb-4 rounded-md bg-green-50 px-4 py-3 text-sm text-green-700">
{{ __('Post updated successfully.') }}
</div>
@endif
<form method="POST" action="{{ route('post.update', $post) }}" class="space-y-6 max-w-2xl">
@csrf
@method('patch')
<div>
<x-input-label for="title" :value="__('Title')" />
<x-text-input id="title" class="mt-1 block w-full" type="text" name="title" :value="old('title', $post->title)" required autofocus autocomplete="off" />
<x-input-error class="mt-2" :messages="$errors->get('title')" />
</div>
<div>
<x-input-label for="slug" :value="__('Slug')" />
<x-text-input id="slug" class="mt-1 block w-full font-mono" type="text" name="slug" :value="old('slug', $post->slug)" required autocomplete="off" />
<x-input-error class="mt-2" :messages="$errors->get('slug')" />
</div>
<div>
<x-input-label for="content" :value="__('Content')" />
<textarea
id="content"
name="content"
rows="10"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
>{{ old('content', $post->content) }}</textarea>
<x-input-error class="mt-2" :messages="$errors->get('content')" />
</div>
<div>
<x-input-label for="status" :value="__('Status')" />
<select id="status" name="status" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
@foreach (\App\Enums\PostStatus::cases() as $status)
<option value="{{ $status->value }}" @selected(old('status', $post->status->value) === $status->value)>
{{ $status->label() }}
</option>
@endforeach
</select>
<x-input-error class="mt-2" :messages="$errors->get('status')" />
</div>
<div class="flex items-center gap-4">
<x-primary-button>{{ __('Save') }}</x-primary-button>
<a href="{{ route('post.index') }}" class="text-sm text-gray-600 underline hover:text-gray-900">
{{ __('Back') }}
</a>
</div>
</form>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,89 @@
<x-app-layout>
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('My Posts') }}
</h2>
<a href="{{ route('post.create') }}" class="inline-flex items-center px-4 py-2 bg-indigo-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150">
{{ __('New Post') }}
</a>
</div>
</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">
<div class="p-6 text-gray-900">
@if (session('status') === 'post-created')
<div class="mb-4 rounded-md bg-green-50 px-4 py-3 text-sm text-green-700">
{{ __('Post created successfully.') }}
</div>
@endif
@if (session('status') === 'post-deleted')
<div class="mb-4 rounded-md bg-green-50 px-4 py-3 text-sm text-green-700">
{{ __('Post deleted successfully.') }}
</div>
@endif
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ __('Title') }}</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ __('Slug') }}</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ __('Status') }}</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ __('Created') }}</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ __('Actions') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
@forelse ($posts as $post)
<tr class="odd:bg-white even:bg-gray-50">
<td class="px-4 py-3 text-sm text-gray-900 max-w-xs truncate">{{ $post->title }}</td>
<td class="px-4 py-3 text-sm text-gray-500 font-mono">{{ $post->slug }}</td>
<td class="px-4 py-3 text-sm">
<span @class([
'inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
'bg-green-100 text-green-800' => $post->status->value === 'published',
'bg-yellow-100 text-yellow-800' => $post->status->value === 'draft',
])>
{{ $post->status->label() }}
</span>
</td>
<td class="px-4 py-3 text-sm text-gray-700">{{ $post->created_at?->format('Y-m-d H:i') }}</td>
<td class="px-4 py-3 text-sm text-gray-700">
<div class="flex items-center gap-3">
<a href="{{ route('post.edit', $post) }}" class="font-medium text-indigo-600 hover:text-indigo-500">
{{ __('Edit') }}
</a>
<form method="POST" action="{{ route('post.destroy', $post) }}" onsubmit="return confirm('{{ __('Delete this post?') }}')">
@csrf
@method('DELETE')
<button type="submit" class="font-medium text-red-600 hover:text-red-500">
{{ __('Delete') }}
</button>
</form>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="5" class="px-4 py-6 text-sm text-center text-gray-500">
{{ __('No posts yet.') }}
<a href="{{ route('post.create') }}" class="text-indigo-600 hover:text-indigo-500">{{ __('Create your first post.') }}</a>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<div class="mt-6">
{{ $posts->links() }}
</div>
</div>
</div>
</div>
</div>
</x-app-layout>