sergioo
sergioo

Reputation: 361

Laravel configuration of "database.php" file not works

i want to connect to database using database.php file, but it's not works. I do not have the .env file. I have to configure something more, beyond the file database.php

file database.php:

<?php
return [

 'default' => env('DB_CONNECTION', 'mysql'),

 'connections' => [

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'my_database'),
        'username' => env('DB_USERNAME', 'mydatabase'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,            
    ],
   ]
 ]

Upvotes: 0

Views: 257

Answers (1)

omar jayed
omar jayed

Reputation: 868

Some of you database connection values are set to take from env file. Since you are not using env, you have to set them in the database.php file manually.

return [

 'default' => env('DB_CONNECTION', 'mysql'),

 'connections' => [

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL', 'Enter your db url here'), <--
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'Your db name'), <--
        'username' => env('DB_USERNAME', 'Db user name'), <--
        'password' => env('DB_PASSWORD', 'Db password'), <--
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,            
    ],
   ]
 ]

Note: You might need to change these settings again for deployment. And you have serve it after changing the file.

Upvotes: 1

Related Questions