63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\CategoryRequest;
|
|
use App\Models\Category;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public function index()
|
|
{
|
|
$this->authorize('viewAny', Category::class);
|
|
|
|
return View::make('categories.index',
|
|
['categories' => Category::all()]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->authorize('create', Category::class);
|
|
|
|
return View::make('categories.create');
|
|
}
|
|
|
|
public function store(CategoryRequest $request)
|
|
{
|
|
$this->authorize('create', Category::class);
|
|
|
|
Category::create($request->validated());
|
|
|
|
return Redirect::route('categories.index');
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|