连接DB在laravel 5中[关闭]

I am trying to learn laravel.I got a problem with db connection.i did everything to connect set host name,user,db and password also but still got error and not able to connect with my DB

Error:

FatalErrorException in MainModel.php line 17: Class 'App\DB' not found

Db Configuration:

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'myblog'),
            'username'  => env('DB_USERNAME', 'root'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

Thanks in advance

It seems that you put the DB connection values in the wrong place. This is how the env function works env($name, $defaultValue)

Basically you're telling env to return 'root' as username, but only if DB_USERNAME doesn't exists. Looking at the error you posted in your comments, it seems that you're trying to connect as homestead, which is usually the default value in your .env file.

If you have a .env file in your root folder, then that's where you should put your values.

You need to import DB class

  use DB;