【发布时间】:2021-08-11 22:57:31
【问题描述】:
您好,我对 Laravel 中的模型 eloquent 有疑问。我该如何改变这一点
SELECT *, CAST(`end` AS int) FROM `Punishments` WHERE (`PunishmentType` = :ban OR `PunishmentType` = :ipBan OR `PunishmentType` = :tempBan OR `PunishmentType` = :tempIpBan) AND (`end` > :now OR `end` = -1) ORDER BY `id` DESC LIMIT :limit OFFSET :offset
到这里
protected Ban $ban;
public function __construct(Ban $ban)
{
$this->ban = $ban;
}
public function getAllBans()
{
return $this->ban
->where('PunishmentType', '=', 'BAN')
->where('PunishmentType', '=', 'IP_BAN')
->where('PunishmentType', '=', 'TEMP_BAN')
->where('PunishmentType', '=', 'TEMP_IP_BAN')
->where('end', '=', -1)
->orWhere('end', '>', time())
->orderBy('id', 'desc')
->paginate(20);
}
这不起作用:(
->where('end', '=', -1)
->orWhere('end', '>', time())
【问题讨论】:
-
使用
orWhere作为惩罚类型? (PunishmentType 不能同时为'BAN'和'IP_BAN') -
是的,但我不知道如何用雄辩的语言做“或”
-
你已经在使用
->orWhere('end', '>', time())
标签: php sql laravel eloquent model