- add category management

This commit is contained in:
2023-07-28 15:43:53 +02:00
parent d47c719d13
commit 8974721c9c
9 changed files with 235 additions and 41 deletions

View File

@@ -9,6 +9,7 @@ use App\Models\Category;
use App\Repository\Interfaces\CategoryRepository;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
use Inertia\Response as InertiaResponse;
class CategoryController
{
@@ -21,42 +22,35 @@ class CategoryController
{
$validate = $request->validated();
if ($this->categoryRepository->update($category, $validate)) {
return back()->with('message', 'Zaktualizowano kategorię!');
return back()
->with('success', 'Zaktualizowano kategorię!');
}
return back()->withError(['message_error', 'Wystąpił błąd podczas aktualizacji!']);
return back()
->with(['error', 'Wystąpił błąd podczas aktualizacji!']);
}
public function store(CategoryRequest $request)
{
// $validate = $request->validated();
// if ($category = $this->categoryRepository->create($validate)) {
// return redirect()
// ->route('admin.category.update', compact('category'))
// ->with('message', 'Utworzono kategorię!');
// }
// return back()->withError(['message_error', 'Wystąpił błąd podczas tworzenia!']);
$category = $this->categoryRepository->create($request->validated());
return redirect()
->route('admin.category.update', compact('category'))
->with('message', 'Utworzono kategorię!');
}
public function create(): View
public function create(): InertiaResponse
{
return view('dashboard.categories.create');
return inertia('Categories/Create');
}
public function edit(Category $category): View
public function edit(Category $category): InertiaResponse
{
return view('dashboard.categories.edit', compact('category'));
return inertia('Categories/Edit', compact('category'));
}
public function delete(Category $category): View
public function delete(Category $category): InertiaResponse
{
return view('dashboard.categories.delete', compact('category'));
return inertia('Categories/ConfirmDelete', compact('category'));
}
public function destroy(Category $category): RedirectResponse
@@ -64,7 +58,9 @@ class CategoryController
$name = $category->name;
$category->delete();
return redirect()->route('admin.home')->with('message', 'Usunięto kategorię "'. $name .'"');
return redirect()
->route('admin.home')
->with('info', 'Usunięto kategorię "'. $name .'"');
}
}