dongqixuan3112 2017-01-17 04:44
浏览 70

如何自动将父ID插入另一个表?

I have a two table named applicants and jobs. I am using Laravel 5.2.

jobs table:

id | job_tittle | email         |...
-----------------------------  
1  | Engineer   | info@mail.com |...

applicants table:

id | job_id | name |...
-----------------------------  
1  |   1    | john |...

Now i want when anyone submit the application form against a job then job_id is auto inserted in the applicants table.

I have tried so far ApplicantController:

$jobAll = Job::all();
$jobId = Job::find($jobAll->first()->id);
//$jobId = $jobAll->first()->id;

DB::table('applicants')->insert([
'job_id' => $jobId,
]);

But its not working.Could anyone tell me how can i do that? Thanks in advance.

  • 写回答

3条回答 默认 最新

  • douyousu9691 2017-01-17 04:46
    关注

    Try this :

    $job = Job::find($id);
    $jodId = $job->id;
    
    DB::table('applicants')->insert([
    'job_id' => $jobId,
    ]);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看