我的脚本有一个问题。我做了foreach文件列表,但我需要分页,例如每个站点15个文件。我现在应该怎么办?感谢帮助 :)
控制器:
$files = Storage::allFiles('/upload_file');
return view('cms.viewSystem.gallery.manageFiles')->with('files', $files);
刀片视图:
<table class="table table-bordered table-striped datatable" id="table-2">
<thead>
<tr>
<th>Nazwa pliku</th>
<th>Akcje</th>
</tr>
</thead>
<tbody>
@foreach($files as $file)
<tr>
<td>{{ $file }}</td>
<td>
<a href="{{ url('cms/media/deleteFile/'.$file) }}" class="btn btn-red btn-sm btn-icon icon-left"><i class="entypo-cancel"></i>Usuń</a>
</td>
</tr>
@endforeach
</tbody>
</table>
我尝试使用paginate()但此选项不起作用:(
您可以做的是:
$page = (int) $request->input('page') ?: 1;
$files = collect(Storage::allFiles('/upload_file'));
$onPage = 15;
$slice = $files->slice(($page-1)* $onPage, $onPage);
$paginator = new \Illuminate\Pagination\LengthAwarePaginator($slice, $files->count(), $onPage);
return view('cms.viewSystem.gallery.manageFiles')->with('files', $paginator);
为了在视图中显示,您可以使用https://laravel.com/docs/5.1/pagination#displaying-results-in-a-view
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句