81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Models\Scopes\BelongsToPlanner;
|
||
|
|
use Database\Factories\UserFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Collection;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||
|
|
use Illuminate\Notifications\Notifiable;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @property int $id
|
||
|
|
* @property int $planner_id
|
||
|
|
* @property string $name
|
||
|
|
* @property Collection<Dish> $dishes
|
||
|
|
* @property Collection<UserDish> $userDishes
|
||
|
|
* @method static User findOrFail(int $user_id)
|
||
|
|
* @method static UserFactory factory($count = null, $state = [])
|
||
|
|
*/
|
||
|
|
class User extends Authenticatable
|
||
|
|
{
|
||
|
|
/** @use HasFactory<UserFactory> */
|
||
|
|
use HasFactory, Notifiable;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'planner_id',
|
||
|
|
'name',
|
||
|
|
'email',
|
||
|
|
'password',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $hidden = [
|
||
|
|
'password',
|
||
|
|
'remember_token',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected static function booted(): void
|
||
|
|
{
|
||
|
|
static::addGlobalScope(new BelongsToPlanner);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the attributes that should be cast.
|
||
|
|
*
|
||
|
|
* @return array<string, string>
|
||
|
|
*/
|
||
|
|
protected function casts(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'email_verified_at' => 'datetime',
|
||
|
|
'password' => 'hashed',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function dishes(): BelongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Dish::class, 'user_dishes', 'user_id', 'dish_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function userDishes(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(UserDish::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function recurrences(): HasManyThrough
|
||
|
|
{
|
||
|
|
return $this->hasManyThrough(
|
||
|
|
UserDishRecurrence::class,
|
||
|
|
UserDish::class,
|
||
|
|
'user_id', // Foreign key on user_dishes
|
||
|
|
'user_dish_id', // Foreign key on user_dish_recurrences
|
||
|
|
'id', // Local key on users
|
||
|
|
'id' // Local key on user_dishes
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|