File manager - Edit - /var/www/html/spdc/api/app/Models/ShelterFamily.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ShelterFamily extends Model { use HasUuids; use HasFactory; const GENDER_MALE = 'Masculino'; const GENDER_FEMALE = 'Feminino'; protected $table = 'shelter_families'; protected $fillable = [ 'establishment', 'name', 'responsible', 'city', 'state', 'number', 'zip_code', 'neighborhood', 'street', 'reference_point', 'longitude', 'latitude', 'observation', 'amount', 'is_homeless', 'cpf', 'rg', 'mother_name', 'father_name', 'living_time_years', 'living_time_months', 'birth_date', 'posto_saude', 'gender', 'nis', 'phone1', 'phone2', 'naturalization', 'tem_cad_unico', 'outros', 'other_benefit', 'other_housing', 'marital_status_id', 'housing_type_id', 'benefit_id', 'shelter_id', 'family_type_id', 'income', 'home_interdiction', 'is_sheltered', 'complement', 'is_unsheltered', 'last_affected' ]; protected $appends = [ 'income_per_person' ]; public function members() { return $this->hasMany(ShelterMemberFamily::class); } public function pets() { return $this->hasMany(FamilyPet::class); } public function shelter() { return $this->belongsTo(Shelter::class); } public function donations() { return $this->hasMany(DonationQuestionnaire::class, 'shelter_families_id', 'id'); } public function familyHealthQuestionnaires() { return $this->hasMany(FamilyHealthQuestionnaire::class, 'shelter_families_id', 'id'); } public function genderString() { return $this->gender === 'M' ? self::GENDER_MALE : self::GENDER_FEMALE; } public function maritalStatus() { return $this->belongsTo(MaritalStatus::class, 'marital_status_id'); } public function housingType() { return $this->belongsTo(HousingType::class, 'housing_type_id'); } public function benefit() { return $this->belongsTo(Benefit::class, 'benefit_id'); } public function emergencyQuestionnaire() { return $this->hasMany(EmergencyQuestionnaire::class, 'shelter_family_id'); } public function familyType() { return $this->belongsTo(FamilyType::class, 'family_type_id'); } public function incomePerPerson(): Attribute { return new Attribute( get: function () { $count = 1; $count += $this->members()->count(); $income = $this->income + $this->members()->sum('income'); $incomePerPerson = $income / $count; return $incomePerPerson; } ); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings