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 :)
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.
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 .
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.
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 !
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:-)
Restart the server, That's all you need to do :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community