From 1e274692e326276768a4b14e25a3c4905203a073 Mon Sep 17 00:00:00 2001 From: Bosun18 Date: Fri, 2 Feb 2024 18:18:58 +0300 Subject: [PATCH] update User.php --- app/Models/User.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index 219ab46..4d4fec8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,8 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class User extends Authenticatable { @@ -43,4 +45,28 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; + + /** + * Get the tasks created by the user. + */ + public function tasks(): HasMany + { + return $this->hasMany(Task::class, 'created_by_id'); + } + + /** + * Get the tasks assigned to the user. + */ + public function assignedTasks(): HasMany + { + return $this->hasMany(Task::class, 'assigned_to_id'); + } + + /** + * Get the labels assigned to the user. + */ + public function labels(): BelongsToMany + { + return $this->belongsToMany(Label::class, 'label_user', 'user_id', 'label_id'); + } }