【问题标题】:Laravel Raw query paginate; raw query to eloquent objectLaravel Raw 查询分页;对雄辩对象的原始查询
【发布时间】:2014-05-18 22:11:53
【问题描述】:
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 说它不是对象

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;
    }

如果至少用 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

感谢您的支持

【问题讨论】:

    标签: php mysql database laravel-4 eloquent


    【解决方案1】:

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

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

    那么你可以使用这样的东西:

    echo $pagination->links();
    

    或者 (Blade) 这个:

    {{ $pagination->links() }}
    

    查看the documentation 了解更多关于手动创建分页的信息。

    【讨论】:

    • 怎么样? @Metra,您需要将array 传递为$books
    猜你喜欢
    • 2018-01-31
    • 2020-03-11
    • 2017-01-05
    • 2016-09-14
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    相关资源
    最近更新 更多