Home > Blockchain >  How to resolve ErrorException: Undefined index: database in laravel?
How to resolve ErrorException: Undefined index: database in laravel?

Time:06-01

i am using laravel and firebase database i want to make my default database connection as a firebase for that i added some details in the config/database.php file when i hit any api it's throwing an following error can you please help me to resolve this issue

<?php

use Illuminate\Support\Str;

return [

  
    'default' => 'firebase',

  
    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],
        'firebase' => array(
            'driver'  =>  'firebase',
            'host'      => 'https://mydomain-34082-default-rtdb.firebaseio.com/',
            'token'     => 'F1tet4K4DjzwAsU9lWTpjyNvYC5kGq49KcxtRAxd',
            'timeout'   => 10,
            'sync'      => false,           // OPTIONAL: auto-sync all Eloquent models with Firebase?
        )

    ],
];

Error

ErrorException: Undefined index: database in file myproj-v8/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php on line 76

CodePudding user response:

I agree with @ml59, Laravel doesn't support firebase as a default driver due to it not being an SQL. as per laravel documentation, it only supports the following 4 databases with the latest laravel 9 version.

  1. MariaDB 10.2
  2. MySQL 5.7
  3. PostgreSQL 10.0
  4. SQLite 3.8.8
  5. SQL Server 2017

Your best option would be to use a library such as https://github.com/mpociot/laravel-firebase-sync, where you can connect Firebase with your application and use SyncsWithFirebase trait to sync with your model.

  • Related