S
S
Sergey Nikolaev2015-07-08 18:40:23
Laravel
Sergey Nikolaev, 2015-07-08 18:40:23

How to connect to database in homestead in laravel?

Created a new project in homestead laravel
In database.php I write the config

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', '192.168.10.10'),
            'database'  => env('DB_DATABASE', 'myDBname'),
            'username'  => env('DB_USERNAME', 'homestead'),
            'password'  => env('DB_PASSWORD', 'secret'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

I'm trying to connect to the database from the controller - it gives out:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.company' doesn't exist (SQL: select * from `company`)

Pounded into the homestead database, despite the fact that in the myDBname config

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-07-08
@Devastor

Does the .env file exist? Most likely in it settings of a DB are registered.
If not, then it's worth trying without env()

'host'      => '192.168.10.10',
            'database'  => 'myDBname',
            'username'  => 'homestead',
            'password'  => 'secret',

It is worth looking in the .env file, or in Homestead.yml for the ENV settings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question