40 lines
1023 B
PHP
40 lines
1023 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Student;
|
|
use App\Rules\UniqueFullNameAtSchool;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use function array_key_exists;
|
|
use function request;
|
|
|
|
class StudentStoreRequest extends FormRequest
|
|
{
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'first_name' => ['required'],
|
|
'last_name' => [
|
|
'required',
|
|
new UniqueFullNameAtSchool(request('first_name'), request('last_name'), Auth::user()->school_id),
|
|
],
|
|
'grade' => ['required', 'integer'],
|
|
'shirt_size' => [
|
|
'nullable',
|
|
function ($attribute, $value, $fail) {
|
|
if (! array_key_exists($value, Student::$shirtSizes)) {
|
|
$fail("The selected $attribute is invalid.");
|
|
}
|
|
},
|
|
],
|
|
];
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|