File manager - Edit - /var/www/html/gop/api/app/Models/Fase.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; class Fase extends BaseModel { protected $fillable = [ 'nome', 'descricao', 'data_inicio', 'data_fim', 'prazo', 'obra_id', ]; protected $appends = [ 'anexos', 'porcentagem', ]; protected function anexos(): Attribute { $images = $this->images; $anexos = [ 'images' => $images, ]; return new Attribute( get: fn () => $anexos, ); } protected function porcentagem(): Attribute { $servicos = $this->servicos; $porcentagemAcumulada = 0; $quantidadeServicos = count($servicos) ?: 1; foreach ($servicos as $servico) { $porcentagemAcumulada = $porcentagemAcumulada + $servico->porcentagem; } $porcentagem = $porcentagemAcumulada / $quantidadeServicos; return new Attribute( get: fn () => $porcentagem, ); } public function obra() { return $this->belongsTo(Obra::class); } public function servicos() { return $this->hasMany(FaseServico::class); } public function images() { return $this->morphMany(Image::class, 'imageable'); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings