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>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?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\SoftDeletes;
|
||||
|
||||
class Idea extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public const STATUSES = ['new', 'considered', 'planned', 'rejected', 'implemented'];
|
||||
|
||||
public const CATEGORIES = ['feature', 'improvement', 'bugfix', 'research', 'other'];
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
'status',
|
||||
'project_id',
|
||||
'priority',
|
||||
'category',
|
||||
'tags',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'priority' => 'integer',
|
||||
];
|
||||
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function scopeNew($query)
|
||||
{
|
||||
return $query->where('status', 'new');
|
||||
}
|
||||
|
||||
public function scopeConsidered($query)
|
||||
{
|
||||
return $query->where('status', 'considered');
|
||||
}
|
||||
|
||||
public function scopePlanned($query)
|
||||
{
|
||||
return $query->where('status', 'planned');
|
||||
}
|
||||
|
||||
public function scopeRejected($query)
|
||||
{
|
||||
return $query->where('status', 'rejected');
|
||||
}
|
||||
|
||||
public function scopeImplemented($query)
|
||||
{
|
||||
return $query->where('status', 'implemented');
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, string $category)
|
||||
{
|
||||
return $query->where('category', $category);
|
||||
}
|
||||
|
||||
public function scopeLinkedToProject($query)
|
||||
{
|
||||
return $query->whereNotNull('project_id');
|
||||
}
|
||||
|
||||
public function scopeUnlinked($query)
|
||||
{
|
||||
return $query->whereNull('project_id');
|
||||
}
|
||||
|
||||
public function scopeSearch($query, string $search)
|
||||
{
|
||||
return $query->where('title', 'like', '%' . $search . '%')
|
||||
->orWhere('description', 'like', '%' . $search . '%')
|
||||
->orWhere('tags', 'like', '%' . $search . '%');
|
||||
}
|
||||
|
||||
public function getTagsArrayAttribute(): array
|
||||
{
|
||||
return $this->tags ? explode(',', $this->tags) : [];
|
||||
}
|
||||
|
||||
public function setTagsAttribute(array|string|null $value): void
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$this->attributes['tags'] = implode(',', $value);
|
||||
} else {
|
||||
$this->attributes['tags'] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user