feat: share flags with Inertia via middleware - #4
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Inertia.js integration to share feature toggle flags with frontend applications. It introduces a middleware that automatically exposes all toggles to Inertia components.
Changes:
- Adds
ShareTogglesWithInertiamiddleware to share feature flags via Inertia props - Updates composer.json to include
inertiajs/inertia-laravelas a dev dependency - Adds documentation for Inertia integration with usage examples
- Applies Laravel Pint code style formatting to
CreateCommand.php
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Middleware/ShareTogglesWithInertia.php | New middleware that extends Inertia's base middleware to share all toggles as 'flags' prop |
| composer.json | Adds inertiajs/inertia-laravel ^2.0 to require-dev dependencies |
| README.md | Documents how to use the new Inertia middleware with code examples |
| src/Commands/CreateCommand.php | Code style formatting changes (spacing, brace placement) via Laravel Pint |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Share all toggles with your frontend by using the provided Inertia middleware. Replace your `HandleInertiaRequests` middleware in `bootstrap/app.php`: | ||
|
|
||
| ```php | ||
| use OffloadProject\Toggle\Middleware\ShareTogglesWithInertia; | ||
|
|
||
| ->withMiddleware(function (Middleware $middleware) { | ||
| $middleware->web(append: [ | ||
| ShareTogglesWithInertia::class, | ||
| ]); | ||
| }) |
There was a problem hiding this comment.
The documentation states "Replace your HandleInertiaRequests middleware" but the code example shows appending the middleware using append: [ShareTogglesWithInertia::class]. This is inconsistent and misleading. The middleware extends Inertia\Middleware and overrides the share method 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.
| class ShareTogglesWithInertia extends Middleware | ||
| { | ||
| /** | ||
| * Share Toggle feature flags with Inertia | ||
| */ | ||
| public function share(Request $request): array | ||
| { | ||
| return [ | ||
| ...parent::share($request), | ||
| 'flags' => Toggle::all(), | ||
| ]; | ||
| } |
There was a problem hiding this comment.
The new ShareTogglesWithInertia middleware lacks test coverage. The project has comprehensive test coverage for other features (as seen in tests/Feature/), and this new middleware should also have tests to verify that it correctly shares toggles with Inertia props. Consider adding a test that verifies the middleware properly calls Toggle::all() and includes the flags in the shared props.
No description provided.