I have a parse error using eloquent with slim3

user86006

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?

Magnus Eriksson

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to access url variable using Slim3 and Eloquent ORM?

Delete query builder in laravel/eloquent using slim3 returning integer 0

Why when I try to use PDO::PARAM_STR in Slim3, Slim return an error?

I have a Parse Error that I cannot get my head around

Pagination with Eloquent-5.3 using Slim 3

I have an error when using Firebase with RecyclearView

I have an error with trigger using if conditional and update

I have an error using group by in postgres?

I have an error using TimestampedGeoJson in folium

why i am getting error as ER_PARSE_ERROR: You have an error in your SQL syntax;

Fatal error: Uncaught Error: Class 'maimana\App' not found -- slim3

Eloquent paginate function in Slim 3 project using twig

Why do i have a "Parse error: syntax error, unexpected T_PUBLIC" in PHP?

I have implemented searchview using with recyclerview but I am getting error?

PHP - Structuring a Slim3 web application using MVC and understanding the role of the model

Laravel error using with() method in Eloquent

How do I catch json parse error when using acceptWithActor?

Parse Error! using wordpress

parse.com promises - do i need to have an "error" function in each "then"?

why do I have a syntax error when using concatenation?

I have an error when using returning data from state in redux

I have get an error when using a function from a class

I have an error with my python discord bot using Dockercompose and Lavalink

I have syntax error when using filter method in ReactJS

Why I have this error: ModuleNotfound error python3

I have to parse JSON response from API using Php, but somethings not working

I'm trying to parse data from a webpage using the importXML function in excel, but the data doesn't have a class

I have this eloquent file, but I receive undefined variable

I have an error using OSMNX: OS error when using ox.graph_from_place