使用 Laravel 5.1 分页从 MySQL 数据库中提取记录
Pulling records from MySQL Db using Laravel 5.1 Pagination
有人请帮助我!如何使用分页呈现数据库的记录?当我尝试根据我正在使用的教程使用此代码时,我在下面收到此错误。我以为结果是 Paginate class.
中的一个方法
<div id="questions">
<h2>Unsolved Questions</h2>
@if(!$questions->results)
<p>No questions have been asked</p>
@else{
<ul>
@foreach($questions->results as $question)
<li>{!! e($question->question) !!}</li>
@endforeach
</ul>
{!! $questions->links !!}
}
@endif
</div>
from ur controller e.g
$question_model = Questions::where('answer_count','=','0')->orderby('created_at','desc')->paginate(5);
in ur front end for pagination
{!! $question_model->render() !!}
这是我作为对@ujwal dhakal 的回复评论发布的问题的解决方案。我想要的是附加提问用户的用户名。
我做的第一件事是将用户集合添加到问题的 index.blade.php
视图,然后遍历它并选择与发布问题的 Auth 用户的用户名相匹配的用户名。
@if(!count($questions) > 0)
<p>No questions have been asked</p>
@else
<ul>
@foreach($questions as $question)
<li>{!! e(str_limit($question->questions, 35)) !!} by
@if(count($users) > 0)
@foreach($users as $user)
@if($user->id === $question->userid)
{!! $user->username !!}
@endif
@endforeach
@endif
</li>
@endforeach
</ul>
{!! $questions->render() !!}
@endif
<div id="questions">
<h2>Unsolved Questions</h2>
@if(!$questions->results)
<p>No questions have been asked</p>
@else{
<ul>
@foreach($questions->results as $question)
<li>{!! e($question->question) !!}</li>
@endforeach
</ul>
{!! $questions->links !!}
}
@endif
</div>
from ur controller e.g
$question_model = Questions::where('answer_count','=','0')->orderby('created_at','desc')->paginate(5);
in ur front end for pagination
{!! $question_model->render() !!}
这是我作为对@ujwal dhakal 的回复评论发布的问题的解决方案。我想要的是附加提问用户的用户名。
我做的第一件事是将用户集合添加到问题的 index.blade.php
视图,然后遍历它并选择与发布问题的 Auth 用户的用户名相匹配的用户名。
@if(!count($questions) > 0)
<p>No questions have been asked</p>
@else
<ul>
@foreach($questions as $question)
<li>{!! e(str_limit($question->questions, 35)) !!} by
@if(count($users) > 0)
@foreach($users as $user)
@if($user->id === $question->userid)
{!! $user->username !!}
@endif
@endforeach
@endif
</li>
@endforeach
</ul>
{!! $questions->render() !!}
@endif