Find two column in laravel which have equal values via Eloquent?
In recent Laravel versions you can use whereColumn
(docs):
$same = Market::whereColumn('seller_id', 'buyer_id')->get();
You need to use whereRaw
to do it:
$market_records = Market::where('seller_id', '!=', Auth::user()->id)
->whereRaw('seller_id = buyer_id')->get();
Anyone looking for this solution keep in mind since Laravel 5.2 it's possible to use whereColumn
method instead, so above code in Laravel 5.2 and up could look like this:
$market_records = Market::where('seller_id', '!=', Auth::user()->id)
->whereColumn('seller_id', 'buyer_id')->get();
You can find details in this commit