retrofairie/app/Http/Requests/CategoryRequest.php
2025-02-21 11:35:53 -08:00

27 lines
596 B
PHP

<?php
namespace App\Http\Requests;
use App\Models\Category;
use Illuminate\Foundation\Http\FormRequest;
class CategoryRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => ['required'],
];
}
public function authorize(): bool
{
if ($this->routeIs('categories.store')) {
return $this->user()->can('create', Category::class);
} elseif ($this->routeIs('categories.update')) {
return $this->user()->can('update', $this->route('category'));
}
return false;
}
}