安装dusterio/lumen-passport执行php artisan migrate时遇config_path()未定义错误
Hey there, let's get this migration error sorted out! The problem boils down to a key difference between Lumen and Laravel: Lumen doesn't include the config_path() helper function by default, but the dusterio/lumen-passport package is trying to use it in its service provider. Here's how to fix it step by step:
Step 1: Add the missing config_path() helper
First, we'll manually define the config_path() function in your bootstrap/app.php file. Drop this code right after the autoload require statement:
<?php require_once __DIR__.'/../vendor/autoload.php'; // Add this helper function here if (!function_exists('config_path')) { function config_path($path = '') { return app()->basePath() . '/config' . ($path ? '/' . $path : $path); } } // Rest of your existing code... try { (new Dotenv\Dotenv(__DIR__.'/../'))->load(); } catch (Dotenv\Exception\InvalidPathException $e) { // ... }
If you don't already have a config folder in your project root, go ahead and create one—this is where we'll store Passport's configuration file.
Step 2: Set up Passport's configuration
Next, we need to get Passport's config file into your config directory. You can do this in one of two ways:
Option A: Use the vendor publish command (if available)
Run this Artisan command in your terminal:
php artisan vendor:publish --provider="Dusterio\LumenPassport\PassportServiceProvider"
This should copy the passport.php config file from the package into your project's config folder.
Option B: Manually copy the config file
If the publish command doesn't work (sometimes Lumen has quirks here), head to vendor/dusterio/lumen-passport/config in your project, copy the passport.php file, and paste it into your root config directory.
Step 3: Verify Passport's service provider is registered
Double-check that you've registered the Passport service provider in bootstrap/app.php:
// Make sure this line exists (usually near the bottom of the file) $app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
Step 4: Run the migration again
Now you should be able to run the migration without errors:
php artisan migrate
That should do it! The missing helper function was the main culprit here—adding it bridges the gap between Lumen's lean setup and the package's Laravel-inspired code.
内容的提问来源于stack exchange,提问作者Garpepi

