Laravel范围的模型自定义场值
我的模型如下
class WorkingTime extends Model
{
protected $table = 'working_times';
protected $fillable = ['day', 'start_time', 'finish_time', 'user_id'];
public function scopeAfterStart($query, $start)
{
return $query->where('start_time', '<=', $start);
}
public function scopeBeforeFinish($query, $finish)
{
return $query->where('finish_time', '>=', $finish);
}
}
,可以使用以下查询,
WorkingTime::afterStart(1200)->beforeFinish(1800)->get();
我需要做的是,在work_times
表中start_time_time
&gt; finish_time
值,我必须检查finish_time + 2400&gt; = $ teright
。更具体地说,必须发生以下查询之类的事情,
with new_working_times as (
select
start_time,
case when start_time > finish_time then
finish_time + 2400
else
finish_time
end as finish_time
)
select * from new_working_times
where finish_time > {finishTime} and start_time < {start_time}
我该如何通过雄辩和范围进行操作?
I have a model as follows
class WorkingTime extends Model
{
protected $table = 'working_times';
protected $fillable = ['day', 'start_time', 'finish_time', 'user_id'];
public function scopeAfterStart($query, $start)
{
return $query->where('start_time', '<=', $start);
}
public function scopeBeforeFinish($query, $finish)
{
return $query->where('finish_time', '>=', $finish);
}
}
and I can use the following query
WorkingTime::afterStart(1200)->beforeFinish(1800)->get();
what I need to do is, in working_times
table when the start_time
> finish_time
value, I have to check if finish_time + 2400 >= $finish
. To be more specific, something like the following query has to be happened
with new_working_times as (
select
start_time,
case when start_time > finish_time then
finish_time + 2400
else
finish_time
end as finish_time
)
select * from new_working_times
where finish_time > {finishTime} and start_time < {start_time}
How can I do this via eloquent and scope?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论