Repository navigation
Replies: 3 comments 1 reply
|
Yes, this is a legitimate issue, though it could be debated whether it's technically a "bug" or a design limitation. Why It's Problematic
Root CauseThe // In SQLiteConnector::parseDatabasePath()
return base_path() . '/' . $path;Solutions & WorkaroundsWorkaround 1: Use Absolute PathsInstead of relative paths, use absolute file paths when configuring SQLite connections: 'database' => '/absolute/path/to/database.sqlite'Workaround 2: Define the Helper FunctionDefine the if (!function_exists('base_path')) {
function base_path($path = '') {
$basePath = __DIR__; // or wherever your app root is
return $basePath . ($path ? DIRECTORY_SEPARATOR . $path : '');
}
}Workaround 3: Use Database Path as Absolute During ConnectionConfigure your SQLite path relative to your known working directory: $config = [
'driver' => 'sqlite',
'database' => __DIR__ . '/database.sqlite'
];
$connectionManager = new Manager($config);Workaround 4: Monkey Patch at RuntimeIf possible, define the function early in your application bootstrap: // In your app's entry point
require_once 'vendor/autoload.php';
if (!function_exists('base_path')) {
function base_path($path = '') {
static $base;
if (!$base) {
$base = dirname(__DIR__);
}
return $path ? $base . DIRECTORY_SEPARATOR . $path : $base;
}
}
// Now use illuminate/databaseRecommendations
|
|
Thanks a lot for the answer. while this is valid: |
|
ai? |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm using the illuminate/database lib as a standalone databaser library in an application, so no Laravel at all.
When trying to connect to a sqlite database file that does not exist I get the error:
Call to undefined function Illuminate\Database\Connectors\base_path()
from the SWLiteConnector::parseDatabasePath() method.
From what I understood base_path is an helper function in Laravel that I obviously not include because I only need the illuminate/database component as a standalone, and never had problems with that.
So I suppose that function should not be used in that library.
Is this a bug?
Thanks
All reactions