30 lines
745 B
PHP
30 lines
745 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Program;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class ProgramRequest extends FormRequest
|
|
{
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required'],
|
|
'category_id' => ['required', 'exists:categories'],
|
|
'description' => ['nullable'],
|
|
'website' => ['nullable'],
|
|
];
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
if ($this->routeIs('programs.store')) {
|
|
return $this->user()->can('create', Program::class);
|
|
} elseif ($this->routeIs('programs.update')) {
|
|
return $this->user()->can('update', $this->route('program'));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|