Aleks12
Aleks12

Reputation: 23

How to add paginate in laravel with relationship?

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

}

Upvotes: 0

Views: 89

Answers (2)

Aji Tirto Prayogo
Aji Tirto Prayogo

Reputation: 21

on the third line in the customerContact() function

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

change to

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

Upvotes: 1

Lessmore
Lessmore

Reputation: 1091

Try this

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

Upvotes: 4

Related Questions