File manager - Edit - /var/www/html/gop/api/app/Models/FaseServico.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; class FaseServico extends BaseModel { protected $table = 'fase_servicos'; protected $fillable = [ 'nome', 'descricao', 'fase_id', 'fiscalizacao_id', ]; protected $appends = [ 'porcentagem', 'anexos', ]; protected function anexos(): Attribute { $images = $this->images; $anexos = [ 'images' => $images, ]; return new Attribute( get: fn () => $anexos, ); } protected function porcentagem(): Attribute { $subitens = $this->subitens; $porcentagemAcumulada = 0; $quantidadeSubitens = count($subitens) ?: 1; foreach ($subitens as $subitem) { $porcentagemAcumulada = $porcentagemAcumulada + $subitem->porcentagemMedida; } $porcentagem = $porcentagemAcumulada / $quantidadeSubitens; return new Attribute( get: fn () => $porcentagem, ); } public function fase() { return $this->belongsTo(Fase::class); } public function subitens() { return $this->hasMany(FaseServicoSubitem::class, 'fase_servico_id', 'id'); } public function images() { return $this->morphMany(Image::class, 'imageable'); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings