【发布时间】:2019-11-20 03:57:57
【问题描述】:
大家好,我已经做了分页编码,但是视图调不出来,谁能指导我? 我的(categoryController.php):
// $tmp = Category::all()->toArray();
$tmp = Category::where('code','like','%' .$codeSearch. '%')->where('description','like','%' .$codeSearch. '%')->paginate(5);
$category = array();
foreach ($tmp as $key => $row) {
$policy = Category::find($row['parent_id']);
$tmpResult = new Category();
$tmpResult->id = $row['id'];
$tmpResult->code = $row['code'];
$tmpResult->description = $row['description'];
$tmpResult->parent_id = $policy['description'];
$tmpResult->status = $row['status'];
array_push($category, $tmpResult);
}
return view('category.index', compact('category'));
}
我的 index.blade.php :
@foreach($category as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['code']}}</td>
<td>{{$row['description']}}</td>
<td>{{$row['parent_id']}}</td>
<td>{{$row['status']}}</td>
<td><a href="{{action('categoryController@edit', $row['id'])}}" class="btn btn-warning">Edit</a></td>
<td>
<form method="post" class="delete_form" action="{{action('categoryController@destroy',$row['id'])}}">
{{ csrf_field() }}
{{ method_field('DELETE')}}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</table>
<div class="container">
@foreach ($category as $row)
{{ $row->name }}
@endforeach
</div>
{!! $category->render() !!}
【问题讨论】:
-
$category->render()应该怎么做?渲染分页器? (这可能无论如何都行不通,因为您使用的是array,它没有分页) -
渲染函数在数组上不可用。它仅在集合中可用。对结果进行分页后,您将它们添加到数组中。这就是您收到该错误的原因。
-
跨度>但即使我使用({{ $category->links() }})这仍然无法为我工作
标签: php laravel eloquent laravel-6