2026-05-07 23:31:33 +02:00
|
|
|
<?php
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-06-16 18:05:53 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2026-05-07 23:31:33 +02:00
|
|
|
|
|
|
|
|
class Phase extends Model
|
|
|
|
|
{
|
2026-06-16 18:05:53 +02:00
|
|
|
use SoftDeletes;
|
|
|
|
|
|
2026-05-07 23:31:33 +02:00
|
|
|
protected $fillable = [
|
2026-06-16 18:05:53 +02:00
|
|
|
'project_id', 'name', 'description', 'order', 'color', 'progress_percent',
|
|
|
|
|
'planned_start', 'planned_end', 'actual_start', 'actual_end'
|
2026-05-07 23:31:33 +02:00
|
|
|
];
|
|
|
|
|
|
2026-06-16 18:05:53 +02:00
|
|
|
protected $casts = [
|
|
|
|
|
'planned_start' => 'date',
|
|
|
|
|
'planned_end' => 'date',
|
|
|
|
|
'actual_start' => 'date',
|
|
|
|
|
'actual_end' => 'date',
|
|
|
|
|
];
|
2026-05-09 22:28:20 +02:00
|
|
|
|
2026-06-16 18:05:53 +02:00
|
|
|
public function project() { return $this->belongsTo(Project::class); }
|
|
|
|
|
public function layers() { return $this->hasMany(Layer::class); }
|
|
|
|
|
public function progressUpdates() { return $this->hasMany(ProgressUpdate::class); }
|
|
|
|
|
public function currentLayer() { return $this->hasOne(Layer::class)->latestOfMany(); }
|
|
|
|
|
public function features() { return $this->hasManyThrough(Feature::class, Layer::class); }
|
|
|
|
|
public function media() { return $this->morphMany(Media::class, 'mediable'); }
|
|
|
|
|
public function images() { return $this->morphMany(Media::class, 'mediable')->where('category', 'image'); }
|
2026-05-09 22:28:20 +02:00
|
|
|
|
2026-06-16 18:05:53 +02:00
|
|
|
public function getDeviationDaysAttribute(): ?int
|
2026-05-09 22:28:20 +02:00
|
|
|
{
|
2026-06-16 18:05:53 +02:00
|
|
|
if (!$this->planned_end) return null;
|
|
|
|
|
$end = $this->actual_end ?? now();
|
|
|
|
|
return $this->planned_end->diffInDays($end, false);
|
2026-05-09 22:28:20 +02:00
|
|
|
}
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|