41 lines
986 B
PHP
41 lines
986 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\School;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class SchoolStoreRequest extends FormRequest
|
|
{
|
|
public function rules(): array
|
|
{
|
|
$schoolId = $this->route('school');
|
|
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
'min:3',
|
|
'max:30',
|
|
Rule::unique('schools', 'name')->ignore($schoolId),
|
|
],
|
|
'address' => ['required'],
|
|
'city' => ['required'],
|
|
'state' => ['required', 'min:2', 'max:2'],
|
|
'zip' => ['required', 'min:5', 'max:10'],
|
|
];
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
if ($this->isMethod('post')) {
|
|
return $this->user()->can('create', School::class);
|
|
}
|
|
if ($this->isMethod('patch')) {
|
|
return $this->user()->can('update', $this->route('school'));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|