I created my database.sqlite file in the database
folder. My .env
file contents are :
DB_CONNECTION=sqlite DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=absolute\path\to\database\database.sqlite DB_USERNAME=admin DB_PASSWORD=
When I run php artisan tinker
and DB::table('users')->get();
I get the info from the database.
My DatabaseController is:
class DatabaseController extends Controller { public function main() { $users = DB::table('users')->get(); return view('database',compact($users)); } }
Yet when I request /database
path I get the error:
QueryException in Connection.php line 647: Database (database/database.sqlite) does not exist. (SQL: select * from "users")
UPDATE: A temporary fix is to change the database.php from the config
folder:
'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => 'absolute\path\database\database.sqlite', 'prefix' => '', ],
Instead of using env('DB_DATABASE', database_path('database.sqlite'))
, which returns database/database.sqlite
not my absolute path.
You need to use full path, something like:
DB_DATABASE=/home/laravel-project/database/database.sqlite
If you remove DB_DATABASE=...
from your .env
file and use the path in the config/database.php
:
'database' => env('DB_DATABASE', database_path('database.sqlite')),...
(if your database.sqlite
file is in database/
folder), it will work, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With