I got this piece of code in Laravel:
public function index()
{
$user_id = auth()->user()->id; // gets the current user id
$user = User::find($user_id); // find the specific user id
$validPosts = $user->posts->paginate(5)->whereIn('status', ['Pending', 'Processing']);
return view('home', compact('validPosts'));
}
I want to return all posts that have the status pending and processing with pagination that has the value of 5 but I am getting the following error:
Method Illuminate\Database\Eloquent\Collection::paginate does not exist.
I know that I have failed somewhere at $user->posts->paginate(5).
What should I do?