2017-05-30 9 views
1

schema_paymentという名前のテーブルがあります。2つの列を持つテーブルからレコードを取得する方法は同じ値ですか?

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(); 

しかし、これらの両方を取得する方法。

答えて

2

あなたがグループ化されたのwheresのカップルを達成しようとしているなら、あなたはこのようなクロージャを使用してそれを行うことができます。

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) 
+0

偉大な、私の問題の歓声のために働いた –

+1

問題なし、うれしかった – Jonathon

1

私はこのようなものは、あなたの答えを与えるべきだと思う:

$payments = AgentPayment::where(['status_change', 1],['verified', 1])->orWhere(['verified',0], ['status_change', 0])->get(); 
関連する問題