-
Notifications
You must be signed in to change notification settings - Fork 1
feat: share flags with Inertia via middleware #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OffloadProject\Toggle\Middleware; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Inertia\Middleware; | ||
| use OffloadProject\Toggle\Facades\Toggle; | ||
|
|
||
| class ShareTogglesWithInertia extends Middleware | ||
| { | ||
| /** | ||
| * Share Toggle feature flags with Inertia | ||
| */ | ||
| public function share(Request $request): array | ||
| { | ||
| return [ | ||
| ...parent::share($request), | ||
| 'flags' => Toggle::all(), | ||
| ]; | ||
| } | ||
|
Comment on lines
+11
to
+22
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states "Replace your
HandleInertiaRequestsmiddleware" but the code example shows appending the middleware usingappend: [ShareTogglesWithInertia::class]. This is inconsistent and misleading. The middleware extendsInertia\Middlewareand overrides thesharemethod to add flags, so it should indeed replace the default HandleInertiaRequests middleware, not be appended to it. The code example should either use a replacement approach or the description should be clarified to indicate that this extends the existing HandleInertiaRequests setup.