$contracts * @property-read int|null $contracts_count * @property-read \Illuminate\Database\Eloquent\Collection $responsibles * @property-read int|null $responsibles_count * @property-read \App\Models\State|null $state * @property-read \App\Models\Unit $unit * @method static \Illuminate\Database\Eloquent\Builder|Student newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Student newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Student onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Student query() * @method static \Illuminate\Database\Eloquent\Builder|Student whereAddressNumber($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereBirthDate($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereCityId($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereComplement($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereDocumentNumber($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereEmail($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereGender($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereHowDidYouKnowUs($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereNeighborhood($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereNotes($value) * @method static \Illuminate\Database\Eloquent\Builder|Student wherePayerName($value) * @method static \Illuminate\Database\Eloquent\Builder|Student wherePhone($value) * @method static \Illuminate\Database\Eloquent\Builder|Student wherePhotoUrl($value) * @method static \Illuminate\Database\Eloquent\Builder|Student wherePostalCode($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereStateId($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereStreet($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereUnitId($value) * @method static \Illuminate\Database\Eloquent\Builder|Student whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Student withTrashed(bool $withTrashed = true) * @method static \Illuminate\Database\Eloquent\Builder|Student withoutTrashed() * @mixin \Eloquent */ class Student extends Model { use HasFactory, SoftDeletes; private ?array $responsibleForCreation = null; protected $table = 'students'; protected $guarded = ['id']; protected $casts = [ 'birth_date' => 'date', 'document_number' => Cpf::class, 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; protected static function booted(): void { static::creating(function (Student $student): void { if ($student->isMinor() && empty($student->responsibleForCreation)) { throw ValidationException::withMessages([ 'responsible' => __('validation.minor_requires_responsible'), ]); } }); } public function withResponsibleForCreation(?array $responsible): self { $this->responsibleForCreation = $responsible; return $this; } public function isMinor(): bool { return $this->birth_date !== null && $this->birth_date->age < 18; } public function contracts(): HasMany { return $this->hasMany(StudentContract::class); } public function responsibles(): HasMany { return $this->hasMany(StudentResponsible::class); } public function unit(): BelongsTo { return $this->belongsTo(Unit::class, 'unit_id'); } public function city(): BelongsTo { return $this->belongsTo(City::class, 'city_id'); } public function state(): BelongsTo { return $this->belongsTo(State::class, 'state_id'); } }