スキーマを持つ 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 のモデルがあります。
今、2つの列に同じ値を持つレコードを取得しようとしています。
単純に私は記録が必要です
status_change = 0 および検証済み = 0
または
status_change = 1 および検証済み = 1
上記のいずれかを次のように簡単に取得できます。
$payments = AgentPayment::where('status_change',1)->where('verified',1)->get();
しかし、これらの両方を取得する方法。
いくつかのグループ化された where を達成しようとしている場合は、次のようなクロージャーを使用して実行できます。
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)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加