我的表架构
+rules
-id
-title
-description
+log
-id
-rules_id
-date MYSQL(YYYY-mm-dd)
我每天执行规则并更新日志表。如何获取今天未执行的规则?
规则模块
public function log()
{
return $this->hasMany('Log');
}
最佳答案
使用whereDoesntHave
:
$rules = Rules::whereDoesntHave('log', function($q){
$q->where('date', Carbon::now()->toDateString());
})->get();
whereDoesntHave
最近才添加(2014 年 12 月)您可能需要更新 Laravel。如果你不能使用这个:
$rules = Rules::whereHas('log', function($q){
$q->where('date', Carbon::now()->toDateString());
}, '<', 1)->get();
关于php - 如何使用 Laravel 4 Eloquent hasMany 关系选择不在日志表上的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28495644/