add relationships for models
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 4m5s Details

This commit is contained in:
aslan 2024-05-29 16:20:22 +03:00
parent 8969b67af8
commit 7901346eb9
5 changed files with 52 additions and 11 deletions

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Note extends Model class Note extends Model
{ {
@ -18,4 +19,9 @@ class Note extends Model
'department_id', 'department_id',
'created_by_id', 'created_by_id',
]; ];
public function task(): BelongsTo
{
return $this->belongsTo(Task::class);
}
} }

View File

@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
class Project extends Model class Project extends Model
@ -24,7 +25,18 @@ class Project extends Model
return $this->belongsTo(Department::class); return $this->belongsTo(Department::class);
} }
public function users() public function users(): BelongsToMany
{ {
return $this->belongsToMany(User::class);
}
public function task_statuses(): hasMany
{
return $this->hasMany(TaskStatus::class);
}
public function tasks(): hasMany
{
return $this->hasMany(Task::class);
} }
} }

View File

@ -27,11 +27,6 @@ class Task extends Model
return $this->belongsTo(User::class, 'created_by_id'); return $this->belongsTo(User::class, 'created_by_id');
} }
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
public function status(): BelongsTo public function status(): BelongsTo
{ {
return $this->belongsTo(TaskStatus::class); return $this->belongsTo(TaskStatus::class);
@ -42,11 +37,6 @@ class Task extends Model
return $this->belongsToMany(Label::class); return $this->belongsToMany(Label::class);
} }
public function department(): BelongsTo
{
return $this->belongsTo(Department::class);
}
public function notes(): HasMany public function notes(): HasMany
{ {
return $this->hasMany('App\Models\Note', 'task_id'); return $this->hasMany('App\Models\Note', 'task_id');
@ -56,4 +46,14 @@ class Task extends Model
{ {
return $this->hasMany('App\Models\Task', 'parent_id'); 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');
}
} }

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class TaskStatus extends Model class TaskStatus extends Model
{ {
@ -15,4 +16,14 @@ class TaskStatus extends Model
'project_id', 'project_id',
'created_by_id', 'created_by_id',
]; ];
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function task(): BelongsTo
{
return $this->belongsTo(Task::class);
}
} }

View File

@ -4,6 +4,8 @@ namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail; // use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
@ -45,4 +47,14 @@ class User extends Authenticatable
'password' => 'hashed', 'password' => 'hashed',
]; ];
} }
public function department(): BelongsTo
{
return $this->belongsTo(Department::class);
}
public function projects(): BelongsToMany
{
return $this->belongsToMany(Project::class);
}
} }