This is my first project on Laravel.
I've been given a distant database to which I try to connect but I can't.
I inserted a test table in phpMyAdmin and I tried to get the data.
I modified the .env file to fill with the database informations.
I created a TestController :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
class Test extends Controller
{
/**
* @return Response
*/
public function index(): string
{
$tests = DB::table('test')->get();
return view('test', ['tests'=>$tests]);
}
}
then I loop on $tests and I try to display the data but I have no result and I get this error :
.env :
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:nAA971RXUyJuOcG2GzTBxKMhqfdNs7j1lGqszq9m CI=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=https://***/
DB_PORT=3306
DB_DATABASE=***
DB_USERNAME=***
DB_PASSWORD=***
database.php :
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
What am I doing wrong ?
CodePudding user response:
you dont need to write HTTPS:// in the DB_HOST just the domain or the IP