33 lines
801 B
PHP
33 lines
801 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\School;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class SchoolStoreRequest extends FormRequest
|
|
{
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'min:3', 'max:30', 'unique:schools,name'],
|
|
'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;
|
|
}
|
|
}
|