'datetime', 'expires_at' => 'datetime', 'remote_allowed' => 'boolean', 'salary_min' => 'decimal:2', 'salary_max' => 'decimal:2', ]; /** * Get the source that provides this job. */ public function source(): BelongsTo { return $this->belongsTo(JobSource::class, 'job_source_id'); } /** * Get the category that this job belongs to. */ public function category(): BelongsTo { return $this->belongsTo(JobCategory::class, 'job_category_id'); } /** * Get the location of this job. */ public function jobLocation(): BelongsTo { return $this->belongsTo(JobLocation::class, 'job_location_id'); } /** * Get the users who saved this job. */ public function savedByUsers(): BelongsToMany { return $this->belongsToMany(User::class, 'user_saved_jobs') ->withTimestamps(); } /** * Scope a query to only include active jobs. */ public function scopeActive($query) { return $query->where(function ($q) { $q->whereNull('expires_at') ->orWhere('expires_at', '>', now()); }); } /** * Scope a query to only include remote jobs. */ public function scopeRemote($query) { return $query->where('remote_allowed', true); } /** * Scope a query to filter by job type. */ public function scopeOfType($query, string $type) { return $query->where('job_type', $type); } /** * Scope a query to filter by experience level. */ public function scopeExperienceLevel($query, string $level) { return $query->where('experience_level', $level); } }