Files
Test-Eloquent-Relationships/app/Models/User.php
T

61 lines
1.2 KiB
PHP
Raw Normal View History

2021-11-22 07:06:44 +02:00
<?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',
];
2021-11-22 07:17:56 +02:00
public function tasks()
{
2021-11-22 07:39:27 +02:00
// TASK: fix this by adding a parameter
2025-04-04 15:43:30 +09:00
return $this->hasMany(Task::class,'users_id');
2021-11-22 07:17:56 +02:00
}
2021-11-22 07:39:27 +02:00
public function comments()
{
// TASK: add the code here for two-level relationship
}
2021-11-22 11:46:59 +02:00
public function projects()
{
return $this->belongsToMany(Project::class)->withPivot('start_date');
}
2021-11-22 07:06:44 +02:00
}