title: Pagination and apply search filters on Raw query in laravel
body: <p>I have a raw query in laravel and I want to convert it into laravel query for apply search filters and pagination on this query.</p>
  
  <pre><code>$transactions = DB::select("
      SELECT transaction1.* FROM ws_transactions transaction1  
      INNER JOIN ws_payment_requests PR  
      ON transaction1.fk_id = PR.id  
      where transaction1.fk_type = 'amount_requesteddd' AND PR.user_id = " . $user-&gt;id . "  
  UNION  
      SELECT transaction2.*  
      FROM ws_transactions transaction2  
      INNER JOIN ws_deal_orders DO ON transaction2.fk_id = DO.id  
      INNER JOIN ws_deals ON ws_deals.id = DO.deal_id  
      where transaction2.fk_type = 'deal_purchasedd' AND ws_deals.user_id = " . $user-&gt;id . "  
  UNION  
      SELECT transaction3.* FROM ws_transactions transaction3  
      INNER JOIN ws_payments PAY ON transaction3.fk_id = PAY.id  
      INNER JOIN users ON users.id = PAY.to_user_id  
      where transaction3.fk_type = 'amount_released' AND users.id = " . $user-&gt;id . "  
  UNION  
      SELECT transaction4.* FROM ws_transactions transaction4  
      INNER JOIN ws_voucher_codes VC ON transaction4.fk_id = VC.id  
      INNER JOIN ws_deal_orders ON ws_deal_orders.id = VC.order_id and VC.class = -1  
      INNER JOIN ws_deals ON ws_deal_orders.deal_id = ws_deals.id  
      where transaction4.fk_type = 'deal_redeemed' AND ws_deals.user_id = " . $user-&gt;id . " AND VC.status = 1  
  UNION  
      SELECT transaction4.* FROM ws_transactions transaction4  
      INNER JOIN ws_voucher_codes VC ON transaction4.fk_id = VC.id  
      INNER JOIN ws_deals ON ws_deals.id = VC.class and VC.class != -1  
      where transaction4.fk_type = 'deal_redeemed' AND ws_deals.user_id = " . $user-&gt;id . " AND VC.status = 1  
      ORDER BY created_at DESC "  
  );
  </code></pre>