51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\CategoryRequest;
|
|
use App\Models\Category;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public function index()
|
|
{
|
|
$this->authorize('viewAny', Category::class);
|
|
|
|
return view('categories.index')->with(['categories' => Category::all()]);
|
|
}
|
|
|
|
public function store(CategoryRequest $request)
|
|
{
|
|
$this->authorize('create', Category::class);
|
|
|
|
return Category::create($request->validated());
|
|
}
|
|
|
|
public function show(Category $category)
|
|
{
|
|
$this->authorize('view', $category);
|
|
|
|
return $category;
|
|
}
|
|
|
|
public function update(CategoryRequest $request, Category $category)
|
|
{
|
|
$this->authorize('update', $category);
|
|
|
|
$category->update($request->validated());
|
|
|
|
return $category;
|
|
}
|
|
|
|
public function destroy(Category $category)
|
|
{
|
|
$this->authorize('delete', $category);
|
|
|
|
$category->delete();
|
|
|
|
return response()->json();
|
|
}
|
|
}
|