edit categories

This commit is contained in:
punkfairie 2025-02-23 12:01:22 -08:00
parent 7971abee3d
commit d9fbd5654b
Signed by: punkfairie
GPG key ID: B3C5488E9A1A7CA6
4 changed files with 52 additions and 3 deletions

View file

@ -43,13 +43,20 @@ public function show(Category $category)
return View::make('categories.show', ['category' => $category]);
}
public function edit(Category $category)
{
$this->authorize('update', $category);
return View::make('categories.edit', ['category' => $category]);
}
public function update(CategoryRequest $request, Category $category)
{
$this->authorize('update', $category);
$category->update($request->validated());
return $category;
return Redirect::route('categories.index');
}
public function destroy(Category $category)

View file

@ -5,7 +5,7 @@
<div class="field-row">
<label for="name">Category Name</label>
<input type="text" id="name" name="name" />
<input type="text" id="name" name="name" value="{{ old('name') }}" />
<x-input-error :messages="$errors->get('name')" />
</div>

View file

@ -0,0 +1,24 @@
<x-layout :title="'Edit Category: '.$category->name">
<x-window>
<form
action="{{ route('categories.update', $category->id) }}"
method="POST"
>
@csrf
@method('PATCH')
<div class="field-row">
<label for="name">Category Name</label>
<input
type="text"
id="name"
name="name"
value="{{ old('name', $category->name) }}"
/>
<x-input-error :messages="$errors->get('name')" />
</div>
<button type="submit">Submit</button>
</form>
</x-window>
</x-layout>

View file

@ -23,6 +23,22 @@
<a href="{{ route('categories.show', $category->id) }}">
View
</a>
@auth
<a
href="{{ route('categories.edit', $category->id) }}"
class="ml-1"
>
Edit
</a>
<a
href="{{ route('categories.destroy', $category->id) }}"
class="ml-1"
>
Delete
</a>
@endauth
</td>
</tr>
@endforeach
@ -30,6 +46,8 @@
</table>
</div>
@auth
<a href="{{ route('categories.create') }}" class="button">New</a>
@endauth
</x-window>
</x-layout>