feat(tasks): complete task management system with Kanban, Calendar, notifications
- Add Task model with subtasks, priorities, status transitions, dates, hours - Add Comment polymorphic model for tasks/issues/projects - Livewire components: TaskManager (list+filters), TaskForm (modal), TaskDetail, TaskKanban (drag&drop), TaskCalendar (FullCalendar) - TaskPolicy with permissions (view/create/edit/delete/assign/manage all) - Notifications: assigned, status change, overdue, comment added - Daily overdue notification job scheduled - Dashboard widget unifies IssueTask + Task - i18n: en/es/fr/ru (393 keys each) - Routes, navigation, offline sync support - 101 tests passing, Pint compliant on new files
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Notifications\TaskCommentNotification;
|
||||
use App\Traits\LogsActivity;
|
||||
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\Relations\MorphTo;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory, LogsActivity;
|
||||
|
||||
protected $fillable = [
|
||||
'commentable_type',
|
||||
'commentable_id',
|
||||
'user_id',
|
||||
'body',
|
||||
'parent_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'body' => 'string',
|
||||
];
|
||||
|
||||
// ============================================================
|
||||
// Events / Observers
|
||||
// ============================================================
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (Comment $comment) {
|
||||
// Notify if comment is on a Task
|
||||
if ($comment->commentable_type === Task::class) {
|
||||
$task = $comment->commentable;
|
||||
if ($task) {
|
||||
// Notify creator and assignee (except the commenter)
|
||||
$usersToNotify = collect([$task->creator, $task->assignee])
|
||||
->unique('id')
|
||||
->filter(fn ($u) => $u && $u->id !== $comment->user_id);
|
||||
|
||||
foreach ($usersToNotify as $user) {
|
||||
$user->notify(new TaskCommentNotification($task, $comment));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Relationships
|
||||
// ============================================================
|
||||
|
||||
public function commentable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Comment::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function replies(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'parent_id')->orderBy('created_at');
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Scopes
|
||||
// ============================================================
|
||||
|
||||
public function scopeTopLevel($query)
|
||||
{
|
||||
return $query->whereNull('parent_id');
|
||||
}
|
||||
|
||||
public function scopeWithReplies($query)
|
||||
{
|
||||
return $query->with('replies.user');
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Accessors
|
||||
// ============================================================
|
||||
|
||||
public function getExcerptAttribute(): string
|
||||
{
|
||||
return strlen($this->body) > 150
|
||||
? substr($this->body, 0, 150).'...'
|
||||
: $this->body;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user