Php 在laravel 5中使用union查询手动分页?
我正在尝试编写手动分页代码,以便与Laravel5中的union一起工作。 我尝试使用代码显示的答案,它显示了如何在使用联合的上下文中使用分页器 在我的视图页面上,分页显示为分页数据,但分页链接工作不正常。如果我点击任何页面链接,它会显示主页。请告诉我我做错了什么 控制器:UnionsController.phpPhp 在laravel 5中使用union查询手动分页?,php,laravel-5,pagination,union,Php,Laravel 5,Pagination,Union,我正在尝试编写手动分页代码,以便与Laravel5中的union一起工作。 我尝试使用代码显示的答案,它显示了如何在使用联合的上下文中使用分页器 在我的视图页面上,分页显示为分页数据,但分页链接工作不正常。如果我点击任何页面链接,它会显示主页。请告诉我我做错了什么 控制器:UnionsController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Suppor
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Input;
use App\Post;
use DB;
class UnionsController extends Controller
{
public function index(){
$page = Input::get('page', 1);
$paginate = 5;
$first = DB::table('movieinfo')
->select('id','movie_name','poster','movie_name1','year','type','season','imdb')
->where('id', '>', 100);
$items = DB::table('tvshows')
->select('id','show_name','poster','show_name1','year','type','season','imdb')
->where('id', '>', 100)
->union($first)
->orderBy('id','desc')
->get();
$slice = array_slice($items->toArray(), $paginate * ($page - 1), $paginate);
return $result = new \Illuminate\Pagination\LengthAwarePaginator($slice, count($items), $paginate, $page);
return view('umoviehub.index')->with('data', $result);
}
}
我为我补充的问题找到了答案
Paginator::resolveCurrentPath()
作为中的最后一个参数
$result = new \Illuminate\Pagination\LengthAwarePaginator($slice, count($items), $paginate, $page, ['path' => Paginator::resolveCurrentPath()]);
正如Arepaginator构造函数所示:
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
$result = new \Illuminate\Pagination\LengthAwarePaginator($slice, count($items), $paginate, $page, ['path' => Paginator::resolveCurrentPath()]);
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])