$recurrences * @property Collection $fixedRecurrences */ class UserDish extends Model { use HasFactory; protected $fillable = ['user_id', 'dish_id']; public function recurrences(): HasMany { return $this->hasMany(UserDishRecurrence::class, 'user_dish_id'); } public function fixedRecurrences(): HasMany { return $this->hasMany(UserDishRecurrence::class, 'user_dish_id') ->where('recurrence_type', WeeklyRecurrence::class) ->join('weekly_recurrences', 'weekly_recurrences.id', '=', 'user_dish_recurrences.recurrence_id') ->select('weekly_recurrences.*', 'user_dish_recurrences.user_dish_id'); // Ensures we work with weekly_recurrences columns } public function user(): BelongsTo { return $this->BelongsTo(User::class); } public function dish(): BelongsTo { return $this->BelongsTo(Dish::class); } }