Did you create the database.sqlite file in the database directory?
After you did that you can migrate the database again
php artisan migrate
Hi
I've created an sqlite database using command
php artisan make:migration create_cards_table --create=cards
and
php artisan migrate
All things was well and I inserted data in my database successfully.
but when I run my code to fetch data from database I faced with this error:
Database (database/database.sqlite) does not exist. (SQL: select * from "cards")
Here is my .env file:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret
and here is my config/database.php file:
'default' => env('DB_CONNECTION', 'sqlite'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
and here is my code:
app/Http/Controllers/CardsController.php
class CardsController extends Controller
{
public function index () {
$cards = DB::table('cards')-> get();
return view('cards.index', compact('cards'));
}
}
resources/views/cards/index.blade.php
@extends ('layout')
@section('content')
@foreach($cards as $card)
<div>{{ $card->title }}</div>
@endforeach
@stop
How can I fix this?
What happens if you remove the DB_DATABASE from your .env file and use the default in config/database.php which is
'database' => env('DB_DATABASE', database_path('database.sqlite')),
Please or to participate in this conversation.