todo/app/Models/Task.php

65 lines
1.4 KiB
PHP
Raw Normal View History

2024-04-27 15:04:24 +03:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2024-05-07 10:35:04 +03:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
2024-04-27 15:04:24 +03:00
class Task extends Model
{
use HasFactory;
2024-05-07 10:35:04 +03:00
protected $fillable = [
'id',
'name',
'description',
'parent_id',
'project_id',
2024-05-07 10:35:04 +03:00
'status_id',
'created_by_id',
];
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
}
2024-06-11 13:17:26 +03:00
public function assigned(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
2024-05-07 10:35:04 +03:00
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');
}
2024-05-29 16:20:22 +03:00
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function files(): HasMany
{
return $this->hasMany('App\Models\File', 'task_id');
}
2024-04-27 15:04:24 +03:00
}