我的分页正确地在第一页上工作。它正确显示2个名称。当我想在下一页上看到其他结果时,它将不显示我当前的代码。当我创建一个静态数组时:
public function zoekdocument(Request $request) //voor het zoeken van software
{
$zoekdocument = \Request::get('zoekdocument');
$searchResult = array();
$searchdoc = \DB::table('visits')->where('title', 'LIKE', '%' . $zoekdocument . '%')->paginate();
foreach($searchdoc as $searchdocument){
$filedir = $searchdocument->pagename; //wordt gedurende loop tot die finisht in de array gezet.
$searchResult[] = $filedir; //dat wordt hier gedaan.
}
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$page = $request->has('page') ? $request->get('page') : 1;
//Create a new Laravel collection from the array data
$collection = new Collection($searchResult);
$perPage = 2;
$currentPageSearchResults = $collection-> slice (($currentPage -1) * $perPage, $perPage)->all();
//Create our paginator and pass it to the view
$paginatedSearchResults= new
LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage, $page, ['path' => $request->url(),'query' => $request->query(),
return view('Documentatie.result', ['results' => $paginatedSearchResults])->with('zoekdocument', $zoekdocument);
它将在不同页面上正确显示数组。 当我从我的SQL查询中创建一个数组时,它在下一页上不显示任何内容。 我使用了var_dump,在第二页上,我没有看到我创建的数组。
这是我的控制器代码:
@section('content')
<!-- Striped rows -->
<div class="panel panel-flat">
<div class="panel-heading">
<h5 class="panel-title text-center">Documentatie overzicht resultaat</h5>
<div class="heading-elements">
</div>
</div>
<div class="text-center">
<h2>Zoekresultaat van: <b><i>{{$zoekdocument}}</b></i></h5>
</div>
@foreach ($results as $result)
<p>{{ $result }}</p>
@endforeach
<?php echo $results->render(); ?>
@endsection
这是我的观看代码:
{{1}}
答案 0 :(得分:1)
我改变了我的代码,为get()更改了paginate(),现在它正常工作。
答案 1 :(得分:0)
我认为以下代码应该通过根据laravel文档显示分页链接来修复错误:
public abstract class GenericDAOImpl<T> implements GenericDAO<T>{
private Class<T> entityBeanType;
@Autowired
protected SessionFactory sessionFactory;
public GenericDAOImpl() {
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
Type type = genericSuperclass.getActualTypeArguments()[0];
@SuppressWarnings("unchecked")
Class<T> clazz = (Class<T>) type;
this.entityBeanType = clazz;
}
@SuppressWarnings("unchecked")
public T save(T t) {
T t1 = (T) sessionFactory.getCurrentSession().merge(t);
sessionFactory.getCurrentSession().flush();
return t1;
}
}
</code>
取代
以下是文档链接:https://laravel.com/docs/5.3/pagination 如果有效,请告诉我,如果没有,我会尝试帮助找到解决方案。