Skip to content

Commit 496ced1

Browse files
committed
Middleware example
1 parent 7a8d4bb commit 496ced1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

v2/data-props/once-props.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ You may also chain `as()`, `fresh()`, and `until()` onto this method.
8484
Inertia::shareOnce('countries', fn () => Country::all())->until(now()->addDay());
8585
```
8686

87-
You may also define a dedicated `shareOnce()` method in your middleware.
87+
You may also define a dedicated `shareOnce()` method in your middleware. The middleware will evaluate both `share()` and `shareOnce()`, merging the results.
8888

8989
```php
9090
class HandleInertiaRequests extends Middleware
9191
{
9292
public function shareOnce(Request $request): array
9393
{
94-
return [
94+
return array_merge(parent::shareOnce($request), [
9595
'countries' => fn () => Country::all(),
96-
];
96+
]);
9797
}
9898
}
9999
```

v2/data-props/shared-data.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ class HandleInertiaRequests extends Middleware
6363
}
6464
```
6565

66-
Alternatively, you may define a dedicated `shareOnce()` method in the middleware.
66+
Alternatively, you may define a dedicated `shareOnce()` method in the middleware. The middleware will evaluate both `share()` and `shareOnce()`, merging the results.
6767

6868
```php
6969
class HandleInertiaRequests extends Middleware
7070
{
7171
public function shareOnce(Request $request): array
7272
{
73-
return [
73+
return array_merge(parent::shareOnce($request), [
7474
'countries' => fn () => Country::all(),
75-
];
75+
]);
7676
}
7777
}
7878
```

0 commit comments

Comments
 (0)