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>
57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Project extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
public const STATUSES = ['active', 'completed', 'archived', 'on_hold', 'planned'];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
'status',
|
|
'due_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'due_at' => 'datetime',
|
|
];
|
|
|
|
public function tasks(): HasMany
|
|
{
|
|
return $this->hasMany(Task::class)->orderBy('priority', 'desc')->orderBy('created_at');
|
|
}
|
|
|
|
public function ideas(): HasMany
|
|
{
|
|
return $this->hasMany(Idea::class)->orderBy('priority', 'desc')->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
public function activeTasks()
|
|
{
|
|
return $this->tasks()->whereIn('status', ['todo', 'in_progress', 'waiting_review']);
|
|
}
|
|
|
|
public function completedTasks()
|
|
{
|
|
return $this->tasks()->where('status', 'done');
|
|
}
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('status', 'active');
|
|
}
|
|
|
|
public function scopeCompleted($query)
|
|
{
|
|
return $query->where('status', 'completed');
|
|
}
|
|
}
|