Files
Test-Eloquent-Relationships/app/Models/User.php
T
2025-04-04 21:43:07 +09:00

62 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function tasks()
{
// TASK: fix this by adding a parameter
return $this->hasMany(Task::class,'users_id');
}
public function comments()
{
// TASK: add the code here for two-level relationship
return $this->hasManyThrough(Comment::class, Task::class,'users_id');
}
public function projects()
{
return $this->belongsToMany(Project::class)->withPivot('start_date');
}
}