2014-01-18 46 views
0

出于某种原因{{$ items-> links()}}没有做任何事情。Laravel - 没有出现分页链接

此问题的直接原因是$ items-> getLastPage()返回0. Same $ items-> getTotal()。

我可以更改网页中的页面参数,它工作正常 - 它进入正确的页面。 但是$ items-> getCurrentPage()在每个页面上返回1。

分页对我来说完全适用于其他模型,只是这个问题给我带来了问题。

另外它似乎工作正常,当我手动创建paginator,但我想能够访问模型中的一些方法,所以我想使用Eloquent模型,而不是原始数组。

编辑: 代码:

$records = EventLog::byObject($model, $id)->paginate(10); 

static public function byObject($model, $id) 
     { 

      $records = DB::select([query], [params]); 
      return self::getHistory($records, $model); 
     } 

static public function getHistory($records, $model = '') 
     { 
      $ids = array(); 
      foreach ($records as $record) { 
       array_push($ids, (int)$record->id); 
      } 

      $history = array();     

      if (count($ids)) { 

       $history = EventLog::whereRaw('id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')', $ids) 
       ->with('creator') 
         ->with(array('eventfields' => function($query) 
         { 
          $query->whereRaw('field NOT LIKE \'%_id\''); 
         })) 
         ->orderBy('event_logs.created_at') 
         ->orderByRaw('(CASE WHEN eventable_type=? THEN 0 ELSE 1 END)', array($model)) 
         ->orderByRaw('(CASE WHEN parent_type=? THEN 0 ELSE 1 END)', array($model)); 

      } 
      return $history; 
     } 

返回$历史有正确的类型,显示正常,但分页不工作的一些原因。

我试图用

{{ $records->links(); }} 

感谢

+0

我们需要你的代码,以帮助您。请在您设置分页的地方发布代码。 – chris342423

+0

@ chris342423我刚刚添加了我的代码。 – GrumpyHat

回答

1

我在这里同样的问题,laravel 4.1与全文搜索的查询范围,显示链接。在我的情况下,问题是orderByRaw(一个正常的顺序不打破分页链接)。

所以我的“穷人”解决办法是保持orderByRaw关闭,当我需要一个分页及用途:

->orderBy(DB::raw('my raw orderby')); 

的作品

+0

我实际上已经想出了自己,并忘记添加在这里,非常感谢! – GrumpyHat