Laravel原始查询分页;原始查询到雄辩的对象 [英] Laravel Raw query paginate; raw query to eloquent object

查看:349
本文介绍了Laravel原始查询分页;原始查询到雄辩的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select '0000-00-00' as date, 'Opening Balance' as narration, (SELECT debit FROM `account_sub_journal` where id=1)as debit, (SELECT credit FROM `account_sub_journal` where id=1)as credit, '0' as transaction_entry_id,'0' as account_sub_journal_id  UNION SELECT * FROM `ledgertransactions` where account_sub_journal_id = 1 and `date` BETWEEN  '2014-04-01' and '2014-04-10'

我目前在模型中作为一个静态函数。我不能分页,因为laravel说它不是一个对象

I currently do this as a static function in model. I couldn't paginate this since laravel says it is not an object

public static function ledgerbook_to($account_id,$date){
        $book =  DB::select( DB::raw("SELECT  '0000-00-00' AS DATE,  'Opening Balance' AS narration, (SELECT debit FROM  `account_sub_journal` WHERE id =1) AS debit, (SELECT credit FROM  `account_sub_journal` WHERE id = :account_id) AS credit,  '0' AS transaction_entry_id,  '0' AS account_sub_journal_id UNION SELECT * FROM  `ledgertransactions` WHERE account_sub_journal_id =:account_id_t and `date` <= :date_to "), array(
   'account_id' => $account_id,'account_id_t' => $account_id,'date_to' => $date));
        return $book;
    }

如果至少可以求解以下查询, >

I could union this if at least solve below query in eloquent.

SELECT  '0000-00-00' AS DATE,  'Opening Balance' AS narration, (SELECT debit FROM  `account_sub_journal` WHERE id =1) AS debit, (SELECT credit FROM  `account_sub_journal` WHERE id =1) AS credit,  '0' AS transaction_entry_id,  '0' AS account_sub_journal_id

感谢您的支持

推荐答案

您可以使用以下方法手动生成分页链接:

You can generate pagination links manually using something like this:

$pagination = Paginator::make($book, count($book), 5);

然后你可以使用这样的:

Then you may use something like this:

echo $pagination->links();

或( Blade )this:

{{ $pagination->links() }}

检查文档,以了解有关创建手动分页。

Check the documentation to know more about creating pagination manually.

这篇关于Laravel原始查询分页;原始查询到雄辩的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆