I use laravel 9 and I have 3 model here :
order
city_id
created_at
updated_at
shop
city_id
accepted_order
shop_id
order_id
notice : accepted_order is not pivot table
class order extends Model {
public function accepted_orders(){
return $this->HasMany(accepted_order::class);
}
}
class shop extends Model {
public function accepted_orders(){
return $this->HasMany(accepted_order::class);
}
}
class accepted_order extends Model {
public function shop(){
return $this->belongsTo(shop::class);
}
public function order(){
return $this->belongsTo(order::class);
}
}
Now I want to get accepted_orders where :
order->updated_at < 4 hour ago if order->city_id == shop->city_id
or
order->updated_at < 2 days ago if order->city_id != shop->city_id
and both query orderBy created_at desc.
how can I use whereHas query that compare two separate relations field with each other?
thanks