You should be able to do something like this:
$perPage = 25; // Or whatever you need
$uploads = Upload::whereHas('user', function ($query) {
$query->where('id', auth()->id());
})->paginate($perPage);
// continue with code as you were
Probably what I am doing in my code is weird, but eventually I need to paginate my output. And in this case I am not sure how...
Here's my code ;
public function uploads() {
$user_id = Auth::id();
$uploads = Upload::whereHas('user', function ($query) use($user_id) {
$query->where('id', $user_id);
})->get();
foreach ( $uploads as $upload) {
$author = Avtor::where('id', $upload->avtor_id)->get();
foreach ( $author as $auth) {
$upload->avtor_id = $auth->name;
}
}
return view('uploads')->with('uploads',$uploads);
}
Any tips on how to apply pagination to $uploads with the current code I have(or what do I need to change in the current code?)?
Please or to participate in this conversation.