Laravel分页render()方法无法正常工作

时间:2017-07-11 09:26:33

标签: php pagination laravel-5.4

我正在做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>

请帮助任何人。提前谢谢

1 个答案:

答案 0 :(得分:0)

试试此代码

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