【问题标题】:Laravel pagination render() method not working correctlyLaravel 分页渲染()方法无法正常工作
【发布时间】:2017-07-11 09:26:32
【问题描述】:

我正在做 CRUD 并想使用分页显示数据。到目前为止,我从 mysql 检索数据,但是当我单击下一步按钮时,路由不起作用。提前感谢您的帮助。下面我正在上传我的代码:

这是我的控制器索引方法

 public function index()
{
   $alldat=DB::select("SELECT a.id as id,a.`name`as name,b.name as catName,(case when a.status=1 then 'Available' else 'out of stock' end) as status FROM `subcategories` a,`categories` b where a.cat_id=b.id");

   $query="SELECT a.id as id,a.`name`as name,b.name as catName,(case when a.status=1 then 'Available' else 'out of stock' end) as status FROM `subcategories` a,`categories` b where a.cat_id=b.id";

    $alldata = new Paginator($alldat, 5, 1);

    return view('admin_theme.dynamic_files.subcategory.allSubCategory',compact('alldata'));
}

这是我的视图刀片文件:

<div class="form-body">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>Id</th>
                            <th>SubCategory Name</th>
                            <th>ParrentCategory Name</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($alldata as $data)
                            <tr class="success">
                                <td>{{$data->id}}</td>
                                <td>{{$data->name}}</td>
                                <td>{{$data->catName}}</td>
                                <td>{{$data->status}}</td>
                                <td><a href="{{route('subcategory.edit',$data->id)}}" class="btn btn-info" role="button">Edit</a>
                                    <a href="" class="btn btn-danger" role="button">Delete</a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    {!!$alldata-> render()!!}
                </div>

请帮助任何人。在此先感谢

【问题讨论】:

  • 当 dd($alldata) ..时你会得到什么?
  • 在 dd give:Paginator {#207 ▼ #hasMore: true #items: Collection {#221 ▼ #items: array:5 [▼ 0 => {#208 ▶} 1 => {# 210 ▶} 2 => {#211 ▶} 3 => {#212 ▶} 4 => {#213 ▶} ] } #perPage: 5 #currentPage: 1 #path: "/" #query: [] #fragment : null #pageName: "页面" }
  • 这里的路径是“/”,我认为应该是解析。有什么想法吗?
  • Raoul Dijksman 请检查一下

标签: php pagination laravel-5.4


【解决方案1】:

试试这个代码

public function index()
{
    $alldata = DB::select(DB::raw("SELECT a.id as id,a.`name`as name,b.name as catName,(case when a.status=1 then 'Available' else 'out of stock' end) as status FROM `subcategories` a,`categories` b where a.cat_id=b.id"));   

    $alldata = $alldata->paginate(5);

    // return code..
}

【讨论】:

  • 我试过但给出:(1/1) FatalThrowableError 调用数组上的成员函数 paginate()
  • no..same error... (1/1) FatalThrowableError 调用数组上的成员函数 paginate()
  • 请注意我的第一条评论...有路径“/”..我需要像主机/routename/?page=2
猜你喜欢
  • 2015-08-26
  • 1970-01-01
  • 1970-01-01
  • 2021-05-04
  • 2018-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-16
相关资源
最近更新 更多