【发布时间】:2017-08-27 11:36:00
【问题描述】:
我有 call_logs 和 jobseekers 表。两个表都有 created_at 列。call_logs 表中有 jobseeker_id。
在 Jobseeker.php 中
public function calllogs()
{
return $this->hasMany('App\Calllog','jobseeker_id');
}
在 Calllog.php 中
public function jobseeker()
{
return $this->belongsTo('App\Jobseeker','jobseeker_id');
}
我想展示一个像
这样的表格created_at call_logs jobseekers
----------------------------------- ---------------------------------
2017-08-05 1 3
2017-08-04 2 2
2017-08-03 3 1
2017-08-02 2 4
2017-08-01 5 8
所以,我可以跟踪记录,每天有多少 call_log 和多少新求职者。 这是我在一张表中尝试的方法,效果很好。但我想一次查询两张表,
$count = DB::table('calllogs')
->select('created_at', DB::raw('count(*) as calllogs'))
->get();
它可以显示给我,比如
created_at calllogs
----------------------------------- ----------
2017-08-03 2
2017-08-04 3
2017-08-05 8
2017-08-06 6
【问题讨论】:
-
向我们展示您的模型和关系。
-
我更新了,请检查一下,@Don'tPanic
标签: php mysql sql laravel laravel-eloquent