douzuan5365 2014-06-14 14:56
浏览 26

访问多个id列,laravel join

I am attempting to join three tables, and access the id column on two of them: Jobs - which shows details and job_interviews which holds the job status - accepted or declined.

Specifically, the problem that I am having is that I need to access both id fields: the jobs.id to allow user to see the details and the job_interviews.id to send his accept or decline response.

I set up my join like this:

public static function respondInterviews($jobID){
    return DB::table('job_interviews')
                ->join('jobs', 'jobs.id', '=', 'job_interviews.job_id')
                ->join('contractors', 'contractors.user_id', '=', 'job_interviews.send_to')
                ->where('jobs.user_id', '=', $jobID)
                ->select('jobs.id', 'job_interviews.id as interview_id', 'jobs.title', 'contractors.user_id', 'contractors.contact_name', 'job_interviews.status', 'jobs.created_at', 'jobs.budget', 'jobs.workType','job_interviews.send_to')
                ->get();
}

I have attempted to set the "id" columns apart by specifying

'job_interviews.id as interview_id',

Then in my page view I iterate through the list of interviews and then call the two id variables:

{{$interview->id}} //which accesses jobs.id and works great
{{$interview->interview_id}} //which is supposed to access job_interviews.id but is not working

The error that laravel is giving me is:

Undefined property: stdClass::$interview_id

How do I access the job_interviews.id column? Thanks in advance for your help.

  • 写回答

1条回答 默认 最新

  • doucheng7808 2014-06-14 15:15
    关注

    Im not familiar with larval but your code looks right. So my solution would to be try changing the name around of the column while doing var_dump($interview) to see its in the object anywhere. The alternative is to double check that the query itself works. Either open a command window to your server or open a tool like mysql workbench and try the query there to make sure everything is coming back fine. If it is a primary key it should be there.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制