Files
muninn/app/Models/Task.php
T
m105andClaude Sonnet 5 a4ff6c0ccb Commit the Projects/Tasks/Ideas/TaskComments feature
This was already implemented, migrated, and running live, but had
never been committed. Bringing it into git: Project/Task/Idea/
TaskComment models, their JSON API (CRUD + status transitions,
task comments, idea<->project linking), Livewire UI pages, and the
nav/route wiring for them. All 42 of its own tests pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-06 20:41:57 +03:00

89 lines
2.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Task extends Model
{
use HasFactory, SoftDeletes;
public const STATUSES = ['todo', 'in_progress', 'done', 'blocked', 'waiting_review'];
protected $fillable = [
'title',
'description',
'status',
'project_id',
'priority',
'due_at',
'started_at',
'completed_at',
'estimated_hours',
'actual_hours',
];
protected $casts = [
'due_at' => 'datetime',
'started_at' => 'datetime',
'completed_at' => 'datetime',
];
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function comments(): HasMany
{
return $this->hasMany(TaskComment::class)->orderBy('created_at');
}
public function scopeByStatus($query, string $status)
{
return $query->where('status', $status);
}
public function scopeTodo($query)
{
return $query->where('status', 'todo');
}
public function scopeInProgress($query)
{
return $query->where('status', 'in_progress');
}
public function scopeDone($query)
{
return $query->where('status', 'done');
}
public function scopeBlocked($query)
{
return $query->where('status', 'blocked');
}
public function scopeWaitingReview($query)
{
return $query->where('status', 'waiting_review');
}
public function scopeDueSoon($query, int $days = 3)
{
return $query->where('due_at', '>=', now())
->where('due_at', '<=', now()->addDays($days))
->where('status', '!=', 'done');
}
public function scopeOverdue($query)
{
return $query->where('due_at', '<', now())
->where('status', '!=', 'done');
}
}