Forms
Post Form Fields code
Copy the implementation or inspect every file that belongs to this component unit.
resources/views/components/ui/post-form-fields.blade.php
@props([
'post' => null,
'categories' => [],
'publishedByDefault' => true,
])
@php
$errorBag = isset($errors) ? $errors : new \Illuminate\Support\ViewErrorBag;
/*
| Shared blog post form fields for create and edit screens.
| Wrap in a <form> and add <x-ui.form-actions> below.
|
| Usage:
| <form ...>
| @csrf
| <x-ui.post-form-fields :categories="$categories" />
| <x-ui.form-actions>...</x-ui.form-actions>
| </form>
|
| <x-ui.post-form-fields :post="$post" :categories="$categories" />
*/
@endphp
<x-ui.field label="Title" for="title" :error="$errorBag->first('title')" required>
<x-ui.input
id="title"
name="title"
:value="old('title', $post?->title)"
:placeholder="$post ? null : 'A catchy headline'"
:invalid="$errorBag->has('title')"
/>
</x-ui.field>
<x-ui.field label="Category" for="category_id" :error="$errorBag->first('category_id')" optional>
<x-ui.select
id="category_id"
name="category_id"
:options="$categories"
:selected="old('category_id', $post?->category_id)"
placeholder="Uncategorized"
:invalid="$errorBag->has('category_id')"
/>
</x-ui.field>
<x-ui.field label="Excerpt" for="excerpt" :error="$errorBag->first('excerpt')" hint="Shown in post lists and page metadata. Leave blank to fall back to the body." optional>
<x-ui.textarea
id="excerpt"
name="excerpt"
rows="3"
:placeholder="$post ? null : 'A concise summary for readers.'"
:invalid="$errorBag->has('excerpt')"
>{{ old('excerpt', $post?->excerpt) }}</x-ui.textarea>
</x-ui.field>
<x-ui.field label="Body" for="body" :error="$errorBag->first('body')" required>
<x-ui.textarea
id="body"
name="body"
rows="12"
:placeholder="$post ? null : 'Write your post...'"
:invalid="$errorBag->has('body')"
>{{ old('body', $post?->body) }}</x-ui.textarea>
</x-ui.field>
<x-ui.checkbox
name="published"
value="1"
:checked="(bool) old('published', $post ? $post->status === \App\Models\Post::STATUS_PUBLISHED : $publishedByDefault)"
:label="$post ? 'Published' : 'Publish immediately'"
/>