50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Category;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of categories.
|
|
*/
|
|
public function index(): View
|
|
{
|
|
$categories = Category::withCount('products')->get();
|
|
|
|
return view('admin.categories.index', compact('categories'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the category.
|
|
*/
|
|
public function edit(Category $category): View
|
|
{
|
|
return view('admin.categories.edit', compact('category'));
|
|
}
|
|
|
|
/**
|
|
* Update the category in storage.
|
|
*/
|
|
public function update(Request $request, Category $category): RedirectResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'icon' => 'nullable|string|max:50',
|
|
'sort_order' => 'nullable|integer',
|
|
]);
|
|
|
|
$category->update($validated);
|
|
|
|
return redirect()->route('admin.categories.index')
|
|
->with('success', "Categorie '{$category->name}' is succesvol bijgewerkt!");
|
|
}
|
|
}
|
|
|