You can eagerload directly:
$contacts = Contact::with(‘company’)->paginate(15);
My experience is that the collection method should accept a Collection of Contacts
Here is the method that should paginate my contacts... but since I have been messing about with relationships, pagination has stopped working and I'm unable to see data.meta in my JSON output in Postman?!
public function index()
{
$contacts = Contact::paginate(15);
return ContactResource::collection($contacts->load('company'));
}
@boyjarv the company relation is already loaded whenever you eager-load with('company')
public function index()
{
$contacts = Contact::with('company')->paginate(15);
return ContactResource::collection($contacts);
}
Please or to participate in this conversation.