my code is:
$type = 10;
$logMp = new SendLog();
$keyword && $logMp->where('msg', 'like', "%{$keyword}%");
$type && $logMp->where(['type' => $type]);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->paginate($size, ['*'], 'page', $page)->toArray();
after i change the code to :
$logMp = new SendLog();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
print_r($logs);die;
for easy to dump the sql,
however , the sql is always like
select * from `send_log` where (`group_id` = ?) order by `id` desc
and as you can see , the type params is disppear, how can i handle this?
$type && $logMp->where('type', $type);
OR
$type && $logMp->where([['type' ,'=', $type]]);
Is this your original code? As setting the $type then using it as an operator for the where doesn't really make sense.
Try to use query()
function instead of creating a new object:
$logMp = SendLog::query();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();