I'm on a Laravel 8 project using the following line in one of my controllers to grab part of a table out of a database:
$post = \DB::table('posts')->where('slug', $slug)->first();
But it gives me this error:
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (SQL: select * from
posts
whereslug
= my-first-post limit 1)
Here's my database connection in my .env file for reference, everything seems correct:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cascade
DB_USERNAME=root
DB_PASSWORD=
What could be wrong here?