当循环遍历集合时,集合将成为对象。循环后当你做{{$wachat->links()}时。您的代码试图对对象进行分页并显示错误。
避免这种问题尝试使用集合变量名复数和对象名单数。
public function wechatshows($d1, $id, $name, Request $request)
{
$users = Keyuser::where('imception_id', '=', $d1)->first();
$user = UserKey::where('id', '=', $id)->first();
if ($name == "all") {
$wachats = Wechat::where('key', '=', $d1)->orderBy('id', 'DESC')->paginate(5);
} else {
$wachats = Wechat::where('key', '=', $d1)->where('groupName', '=', $name)->orderBy('id', 'DESC')->paginate(5);
}
$wechatcontact = Wechat::select('groupName')->groupBy('groupName')->get();
return view('wechat.show', ['wachats' => $wachats, 'user' => $user, 'product' => $d1, 'users' => $users, 'keyUser' => $d1, 'wechatcontact' => $wechatcontact]);
}
和
<tbody id="chatListBody" style="overflow-y: scroll;">
@foreach ($wachats as $wachat)
<tr>
<input type="hidden" class="wechatname" data-id="{{ $wachat->id }}">
<td>{{ $wachat->id }}</td>
<td>{{ $wachat->wxid }}</td>
<td>{{ $wachat->username }}</td>
@if ($wachat->type === 'image')
<td><a class="example-image-link" href="{{ url('/images/'.$wachat->imgPath.'') }}" data-lightbox="{{$wachat->imgPath}}"
data-title="{{$wachat->imgPath}}"><img class="imgwhatsapp" data-lightbox="roadtrip" src="{{ url('/images/'.$wachat->imgPath.'') }}"></a></td>
@elseif ($wachat->type === 'video')
<td><a href="{{ url('/images/'.$wachat->imgPath.'') }}">{{$wachat->imgPath}}</a></td>
@elseif ($wachat->type === 'audio')
<td> <a href="{{ url('/images/'.$wachat->imgPath.'') }}">{{$wachat->imgPath}}</a> </td>
@elseif ($wachat->type === 'text')
<td>{{$wachat->message}}</td>
@else
<td>no data</td>
@endif
<td>{{ $wachat->created_at }}</td>
</tr>
@endforeach
</tbody>
{{ $wachats->links() }}
</div>
</table>