#4-merge-with-master-conflict-resolve
This commit is contained in:
80
app/Http/Controllers/CategoryController.php
Normal file
80
app/Http/Controllers/CategoryController.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreCategoryRequest;
|
||||
use App\Http\Requests\UpdateCategoryRequest;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of categories.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$categories = Category::query()
|
||||
->latest()
|
||||
->paginate(10, ['id', 'name', 'slug', 'description', 'color', 'created_at']);
|
||||
|
||||
return view('category.index', [
|
||||
'categories' => $categories,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new category.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('category.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created category.
|
||||
*/
|
||||
public function store(StoreCategoryRequest $request): RedirectResponse
|
||||
{
|
||||
Category::query()->create($request->validated());
|
||||
|
||||
return redirect()
|
||||
->route('category.index')
|
||||
->with('status', 'category-created');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified category.
|
||||
*/
|
||||
public function edit(Category $category): View
|
||||
{
|
||||
return view('category.edit', [
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified category.
|
||||
*/
|
||||
public function update(UpdateCategoryRequest $request, Category $category): RedirectResponse
|
||||
{
|
||||
$category->update($request->validated());
|
||||
|
||||
return redirect()
|
||||
->route('category.edit', $category)
|
||||
->with('status', 'category-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified category.
|
||||
*/
|
||||
public function destroy(Category $category): RedirectResponse
|
||||
{
|
||||
$category->delete();
|
||||
|
||||
return redirect()
|
||||
->route('category.index')
|
||||
->with('status', 'category-deleted');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user