简体   繁体   中英

How to get the not applied jobs in the job table laravel

$joblist = JobDetail::join('candidates', 'job_details.id', '=', 'candidates.job_detail_id')
    ->where('candidates.user_id', Auth::id())
    ->where('candidates.job_detail_id', null)
    ->get();

SELECT job_details.* 
FROM job_details 
LEFT JOIN candidates 
ON job_details.id = candidates.job_detail_id 
WHERE candidates.job_detail_id IS NULL AND candidates.user_id = Auth::id()

This SQL query is not working.
I want to get the jobs that user didn't apply

jobs and users mapping table - candidate table

job details table

Consider fetching jobList from the candidate table :

$joblist = candidates::leftjoin('JobDetail','candidates.job_detail_id','job_details.id')
->where('candidates.user_id',Auth::id())
->whereNull('job_detail_id')
->select('job_details.*')->get();

------------job details model---------------

public function candidates(){
     return $this->hasMany(candidate::class);
}

------------controller logic---------------

$userId = Auth::id();


$joblist = JobDetail:: whereDoesntHave('candidates', function ($query) use ($userId){ 
     $query->where('user_id', $userId); 
})->select('job_details.*')->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM