Home > Net >  How to add paginate in laravel with relationship?
How to add paginate in laravel with relationship?

Time:09-22

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,
    ]);

}

CodePudding user response:

Try this

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

CodePudding user response:

on the third line in the customerContact() function

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

change to

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