phase 4
This commit is contained in:
@@ -108,4 +108,83 @@ class Job extends Model
|
||||
{
|
||||
return $query->where('experience_level', $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to search by keywords in title, company, and description.
|
||||
*/
|
||||
public function scopeSearchKeywords($query, string $keywords)
|
||||
{
|
||||
return $query->where(function ($q) use ($keywords) {
|
||||
$q->where('title', 'LIKE', "%{$keywords}%")
|
||||
->orWhere('company', 'LIKE', "%{$keywords}%")
|
||||
->orWhere('description', 'LIKE', "%{$keywords}%");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter by category.
|
||||
*/
|
||||
public function scopeInCategory($query, int $categoryId)
|
||||
{
|
||||
return $query->where('job_category_id', $categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter by location.
|
||||
*/
|
||||
public function scopeInLocation($query, string $location)
|
||||
{
|
||||
return $query->where(function ($q) use ($location) {
|
||||
$q->where('location', 'LIKE', "%{$location}%")
|
||||
->orWhereHas('jobLocation', function ($q2) use ($location) {
|
||||
$q2->where('city', 'LIKE', "%{$location}%")
|
||||
->orWhere('state', 'LIKE', "%{$location}%")
|
||||
->orWhere('country', 'LIKE', "%{$location}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter by salary range.
|
||||
*/
|
||||
public function scopeWithinSalaryRange($query, ?float $minSalary = null, ?float $maxSalary = null)
|
||||
{
|
||||
if ($minSalary) {
|
||||
$query->where(function ($q) use ($minSalary) {
|
||||
$q->where('salary_max', '>=', $minSalary)
|
||||
->orWhereNull('salary_max');
|
||||
});
|
||||
}
|
||||
|
||||
if ($maxSalary) {
|
||||
$query->where(function ($q) use ($maxSalary) {
|
||||
$q->where('salary_min', '<=', $maxSalary)
|
||||
->orWhereNull('salary_min');
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter by posted date.
|
||||
*/
|
||||
public function scopePostedWithin($query, int $days)
|
||||
{
|
||||
return $query->where(function ($q) use ($days) {
|
||||
$q->where('posted_at', '>=', now()->subDays($days))
|
||||
->orWhere(function ($q2) use ($days) {
|
||||
$q2->whereNull('posted_at')
|
||||
->where('created_at', '>=', now()->subDays($days));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter by company.
|
||||
*/
|
||||
public function scopeByCompany($query, string $company)
|
||||
{
|
||||
return $query->where('company', 'LIKE', "%{$company}%");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user