I'm following the codecourse video series Authentication with Slim 3, which is about 3 years old. I've hit a snag when it comes to using eloquent to access a mysql database. (the relevant video: https://www.youtube.com/watch?v=70IkLMkPyPs )
the code wasn't quite the same as that currently recommended on the instructions on illuminate/database's docs, so I've modified the code slightly to follow that standard, but regardless of whether I follow Alex's code oon the vid or the following, a parse error results.
$app = new \Slim\App([
'settings' => [
'displayErrorDetails' => true,
'db' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'opium3',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]
],
]);
$container = $app->getContainer();
/*set up eloquent to use outside laravel*/
use \Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
Running the app produced this error:
Parse error: syntax error, unexpected '=' in /var/www/public/opium3/vendor/illuminate/database/DatabaseManager.php on line 65
I'm running this locally on a scotchbox vagrant set up, if that's relevant. There's a similar question at Parse error when run illuminate/database/capsule with bootEloquent() in PHP
but this answer doesn't resolve my issue, since the server is running php7. I have also tried installing packages recommended by illuminate/database, installing php-mbstring, and editing the php.ini file, on the server, but the error persists.
Am I missing something obvious?
Make sure you're using at least PHP 7.1.
/illuminate/database/DatabaseManager.php
is using a short hand version of the list()
-construct which wasn't available until PHP 7.1.
The "old" way is to:
list($var1, $var2) = someFunction();
while you, since PHP 7.1, can also do:
[$var1, $var2] = someFunction();
The row the error is thrown in is this:
[$database, $type] = $this->parseConnectionName($name);
Note:
If you can't upgrade your PHP version from 7.0 to 7.1.3+, you need to use an older version of the Illuminate/Database
-package. Use version 5.5 for PHP 7.0 and then 5.6+ on PHP 7.1.3+
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments