我有一个名为agent_payment的表,其中包含架构。
Schema::create('agent_payment', function (Blueprint $table) {
$table->increments('id');
$table->integer('agent_id');
$table->integer('created_by');
$table->integer('rid')->nullable()->comment('Only For Admin Reservation');
$table->string('date');
$table->string('paid_amount');
$table->string('paid_by')->nullable();
$table->string('received_by')->nullable();
$table->enum('type',['cash','cheque']);
$table->string('bank_name')->nullable();
$table->string('cheque_num')->nullable();
$table->string('deposited_to')->nullable();
$table->string('account_num')->nullable();
$table->string('slip')->nullable();
$table->integer('verified')->default(0)->comment('Verified 1 Unverified 0');
$table->integer('status_change')->default(0);
$table->string('reject_message')->nullable();
$table->timestamps();
});
我有此表AgentPayment的模型。
现在,我正在尝试在两列中获取具有相同值的记录。
我只需要
记录status_change = 0且已验证= 0
或
status_change = 1且已验证= 1
很容易得到上述任何一个:
$payments = AgentPayment::where('status_change',1)->where('verified',1)->get();
但是如何获得这两者。
答案 0 :(得分:2)
如果你想要实现几个分组,那么你可以使用这样的闭包来做到这一点:
AgentPayment::where(function($query) {
return $query->where('status_change', 1)->where('verified', 1);
})->orWhere(function($query) {
return $query->where('status_change', 0)->where('verified', 0);
})->get();
这应该导致查询看起来像:
select * from agent_payment where (status_change = 1 AND verified = 1) OR (status_change = 0 AND verified = 0)
答案 1 :(得分:1)
我认为这样的事情会给你答案:
$payments = AgentPayment::where(['status_change', 1],['verified', 1])->orWhere(['verified',0], ['status_change', 0])->get();