【发布时间】: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