- add category management
This commit is contained in:
@@ -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 .'"');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Requests\ProjectRequest;
|
||||
|
Reference in New Issue
Block a user