简体   繁体   中英

Laravel 5.4 : 500 Internal Server Error when accessing localhost API

i tried to call localhost API in my application using guzzle, but i got this error:

ServerException in RequestException.php line 111:
Server error: `GET http://localhost/WingsFeedAPI/public/products` resulted 
in a `500 Internal Server Error` response:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow (truncated...)

the API made with https://github.com/ellipsesynergie/api-response , and when i access http://localhost/WingsFeedAPI/public/products it returns :

// 20170517054157
// http://localhost/WingsFeedAPI/public/products

{
  "data": [
    {
      "id": 1,
      "nama_barang": "Daging ayam",
      "harga_barang": "5000",
      "rating": "123",
      "jenis_barang": "daging",
      "expired": "2017-05-03"
    }
  ]
}

And this is how i call that API in my application

Controller :

public function index()
{
    $client = new \GuzzleHttp\Client();
    $res = $client->request('GET','http://localhost/WingsFeedAPI/public/products');
    echo $res->getBody();
}

Route :

Route::get('/', 'WelcomeController@index');

I got the solution from here ; it requires the following steps;

The first one: to remove section below from the .env file,

DB_CONNECTION=mysql
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

The second one, to define in the config/database.php file the MySQL database parameters.

The snippet below highlights the portion to be edited for the database configuration a referred right above;

'mysql' => [
    'driver' => 'mysql',
    'host' => '',
    'database' => '',
    'username' => '',
    'password' => '',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => false,
],

Laravel appears to be working fine. See comments for discussion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM