Skip to content

Eager Loading

Gilberto Junior edited this page Dec 4, 2019 · 5 revisions

The same as found in the Laravel Documentations.

With

Syntax

public function with(string $relation1, string $relation2, ...): self;
public function with(array|string $relations): self;

Example 1

Simple relationship:

$repository->with('users');

Example 2

Multiple relationships:

$repository->with('users', 'stores');

// or

$repository->with(['products', 'categories', 'brands']);

// or

$repository->with('users,companies,customers');

Example 3

Nested relationships:

$repository->with('author.contacts');

🡄 Offset | Outputs 🡆