dstpabuaran.com/app/Http/Controllers/Admin/Master/CategoryController.php
Yoga Pangestu e93fd181ee feat: implement category management with CRUD functionality and integrate sluggable for SEO-friendly URLs
- Added CategoryController for handling category operations.
- Created CategoryRequest for validation of category data.
- Introduced CategoryService for business logic related to categories.
- Implemented sluggable functionality in the Category model for automatic slug generation.
- Developed UI components for category management, including a data table and dialogs for creating and editing categories.
- Updated routes to include resourceful routes for categories.
2026-07-29 01:11:53 +07:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Master;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Master\CategoryRequest;
use App\Models\Category;
use App\Services\Admin\Master\CategoryService;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;
class CategoryController extends Controller
{
public function __construct(
private CategoryService $service
) {}
public function index(): Response
{
return Inertia::render('admin/master/category/index', [
'categories' => $this->service->getAll(),
]);
}
public function store(CategoryRequest $request): RedirectResponse
{
$this->service->create($request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil ditambahkan.']);
return to_route('admin.master.categories.index');
}
public function update(CategoryRequest $request, Category $category): RedirectResponse
{
$this->service->update($category, $request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil diperbarui.']);
return to_route('admin.master.categories.index');
}
public function destroy(Category $category): RedirectResponse
{
$this->service->delete($category);
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kategori berhasil dihapus.']);
return to_route('admin.master.categories.index');
}
}