Support the ongoing development of Laravel.io →
Configuration Database Eloquent

Well I'm new to laravel, & still learning it. Basically when i use php artisan migrate, it migrates normally. This shows that my db is already connect with the app. I had before the same problem when I tried to migrate so changed my db's information on .env & .env.example then it worked ! I faced the problem when i connected the DB using a controller, when I tried to load it on the browser, got that error message

here is the controller

public function index()
	{
		$users = array();

		$users = DB::table('users')->get();

		return view('user.index', compact('users'));
	}

here is my DB

'connections' => [

		'sqlite' => [
			'driver'   => 'sqlite',
			'database' => storage_path().'/database.sqlite',
			'prefix'   => '',
		],

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

	],

The .env file

APP_ENV=local
APP_DEBUG=true
APP_KEY=c87CmMxkDXE3nlPTcr8AaZGFYsf5juH3

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file

The .env.example file

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file

Thank u for any help :)

Last updated 3 years ago.
0
Solution

If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

0

byjml said:

If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

Thank u, u just saved my life .

0

byjml said:

If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

Thanks, is totally work for me.

0

byjml said:

If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

thanks a lot its work !

0

thank you it's working

0

byjml said: If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

Worked on the first try, thanks a lot dear:-)

Last updated 6 years ago.
0

Restart the server, That's all you need to do :)

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Bouhoum bouhoum Joined 14 Feb 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.