skip to Main Content

i have a table name merge_jobs and another table name employer_jobs.

merge_jobs has a column called employer_id which matches with user_id column in employer job

merge_job table also have a column called user_id

So I want to get rows where the user_id in merge_jobs matches the authenticated user where employer_id of the selected rows matches the user_id of the employer_jobs

I tried to use left join but did not work

My code

  $jobs = DB::table('job_mergings')
    ->leftJoin('employer_jobs', function($join)
    {
        $join->on('job_mergings.employer_id', '=', 'employer_jobs.user_id');

    })
    ->where('job_mergings.user_id', '=', Auth::user()->id)
    ->get();

2

Answers


  1. I think there’s just a mistake in your query and you should correct it like this:

    ->where('job_mergings.employer_id', '=', Auth::user()->id)
    
    Login or Signup to reply.
  2. you can get the authenticated user id from the request like this

    ->where('job_mergings.employer_id','=',$request->user()->id)->get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search