todo/app/Models/Task.php

65 lines
1.4 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\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Task extends Model
{
use HasFactory;
protected $fillable = [
'id',
'name',
'description',
'parent_id',
'project_id',
'status_id',
'created_by_id',
];
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
}
public function assigned(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
public function status(): BelongsTo
{
return $this->belongsTo(TaskStatus::class);
}
public function labels(): BelongsToMany
{
return $this->belongsToMany(Label::class);
}
public function notes(): HasMany
{
return $this->hasMany('App\Models\Note', 'task_id');
}
public function subTasks(): HasMany
{
return $this->hasMany('App\Models\Task', 'parent_id');
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function files(): HasMany
{
return $this->hasMany('App\Models\File', 'task_id');
}
}