我有2个查询
$a = Message::where('conversation_id',$id)->where('user_id',$user->id)->where('s_1',1)
->get();
$b = Message::where('user_id',$conversation->recipients()->last()->user->id)->where('s_1',1)
->get();
$result = $a->merge($b);
$messages = $result;
所有我都将var消息传递给视图,但在视图中,方法呈现或链接不起作用以对结果进行分页:
<table class="table table-hover">
@foreach($messages as $i => $message)
<tr>
<td>
<img src="{{$avatar[$message->user->username]}}" class="aoi pull-left" />
<a href="{{route('profile',[$message->user->username])}}">{{ $message->user->name }}</a>
- <script>
moment.locale("es");
document.writeln(moment.utc("{{ $message->created_at }}", "YYYYMMDD hh:mm:ss").fromNow());
</script>
<br>
{{ $message->body }}
</td>
</tr>
@endforeach
</table>
{!! str_replace('/?', '?', $messages->render()) !!}
答案 0 :(得分:0)
你必须使用paginate()函数来获取你的记录。
你应该试试这个。$b = Message::where('user_id',$conversation->recipients()->last()->user->id)->where('s_1',1)
->orderBy('user_id','desc')->paginate(10);
这将自动获取()与您的查询匹配的记录,以及 你只需要做分页,
{{$b->appends(request()->input())->links()}}
如果记录超过您的分页限制(10),这将自动提供指向下一页的链接。