aahoora
2 years ago
132
18
General

Database (database/database.sqlite) does not exist" error on running

Posted 2 years ago by aahoora

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?

Please sign in or create an account to participate in this conversation.