How to add paginate in laravel with relationship?

Viewed 48

I need to paginate this where I need to find id but i don't know how.

    function customerContact($id)
{

    $customers = Customer::with('contacts')->find($id);

    return Inertia::render('Customers/Contacts/Index', [
        'customers' => $customers,
    ]);

}
2 Answers

Try this

$customers = Customer::find($id)->contacts()->paginate();

on the third line in the customerContact() function

$customers = Customer::with('contacts')->find($id);

change to

$customers = Customer::find($id)->contacts()->paginate();
Related