phpete1/inertia-configurator

Share Laravel config files with Inertia Vue frontend

Installs: 27

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/phpete1/inertia-configurator

v1.0.1 2025-10-28 17:31 UTC

This package is auto-updated.

Last update: 2025-11-28 17:37:41 UTC


README

Automatically share Laravel config files with your Inertia Vue frontend securely using the .inertia.php naming convention.

How It Works

Any config file ending with .inertia.php is automatically shared with Inertia under the config prop. The .inertia suffix is removed from the key name.

💡 Important: Public Configuration Only

The .inertia.php naming convention is intentional - it clearly identifies config files that will be sent to the frontend and visible to users.

NEVER include sensitive information in .inertia.php files:

  • API keys or secrets
  • Database credentials
  • User personal data
  • Authentication tokens
  • Internal system paths
  • Private business logic

Only share public, non-sensitive configuration values like app name, feature flags, or UI settings.

Installation

composer require phpete1/inertia-configurator

Setup

1. Register Middleware

Option A: Global (All Web Routes)

Add the middleware to your bootstrap/app.php:

->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \Phpete1\InertiaConfigurator\Middleware\InertiaConfiguratorMiddleware::class,
    ]);
})

Option B: Route Level (Specific Routes)

Apply to specific routes in routes/web.php:

Route::middleware([\Phpete1\InertiaConfigurator\Middleware\InertiaConfiguratorMiddleware::class])
    ->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index']);
        // other routes...
    });

2. Publish Vue Composable

php artisan vendor:publish --tag=inertia-configurator

This creates resources/js/composables/useConfig.ts.

Testing

1. Create a config file

Create config/colors.inertia.php:

<?php

return [
    'default' => 'Blue!',
];

2. Use in Vue

That's it! No controller changes needed. The config is automatically available:

<script setup>
import { useConfig } from '@js/composables/useConfig'

const color = useConfig('colors')
console.log(color.default) // Output: Blue!
</script>

License

MIT