edit categories
This commit is contained in:
parent
7971abee3d
commit
d9fbd5654b
4 changed files with 52 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
24
resources/views/categories/edit.blade.php
Normal file
24
resources/views/categories/edit.blade.php
Normal 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>
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue