$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
Advertisement
Answer
————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();