$dishes * @property Collection $userDishes * @method static User findOrFail(int $user_id) * @method static UserFactory factory($count = null, $state = []) * @method static create(array $array) * @method static where(string $string, int|string|null $id) */ class User extends Model { /** @use HasFactory */ use HasFactory; protected $fillable = [ 'planner_id', 'name', ]; protected static function booted(): void { static::addGlobalScope(new BelongsToPlanner); } 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 ); } }