更新时间:2022-06-10 08:32:27
我通常会为此重写 newQuery()
.newQuery()
是 Eloquent 用来构造新查询的方法.
I normally override newQuery()
for this. newQuery()
is the method that Eloquent use to construct a new query.
class News extends Eloquent {
public function newQuery($excludeDeleted = true) {
return parent::newQuery($excludeDeleted)
->where(status, '=', 1);
}
}
现在您的 News::all()
将只输出您的状态 = 1 的新闻.
Now your News::all()
will only output your news with status = 1.