Parse error when run illuminate/database/capsule with bootEloquent() in PHP

左心房为你撑大大i 提交于 2019-12-12 06:52:45

问题


I'm trying to make a mysql connection within a php environment using Slim and the package illuminate/database. Following the documentation I have created a new $capsule instance, I have passed the array with connection data through the addConnection method and then I have run bootEloquent() method:

<?php

use Illuminate\Database\Capsule\Manager as Capsule;


$capsule = new Capsule;

$capsule->addConnection([
  'driver' => $app->config->get('db.driver'),
  'host' => $app->config->get('db.host'),
  'database' => $app->config->get('db.database'),
  'username' => $app->config->get('db.username'),
  'password' => $app->config->get('db.password'),
  'charset' => $app->config->get('db.charset'),
  'collation' => $app->config->get('db.collation'),
  'prefix' => $app->config->get('db.prefix')
]);

#here the output seems correct...
#var_dump($capsule);

$capsule->bootEloquent();


 ?>

Unfortunately when I run bootEloquent() it goes through an error:

Parse error: parse error in /Sites/auth/vendor/illuminate/database/Eloquent/Model.php on line 597

The problem seems related to the Eloquent Model. I have already tried to update the composer.json file with different versions. I have also installed again each package, but the parse error still remains.

Currently the project is running on: PHP Version 5.6.30.

My current composer json file with all dependencies

{
    "autoload": {
      "psr-4": {
        "Business\\": "app/Business"
      }
    },
    "require": {
        "slim/slim": "~2.0",
        "slim/views": "0.1.*",
        "twig/twig": "~1.0",
        "phpmailer/phpmailer": "~5.2",
        "hassankhan/config": "0.8.*",
        "illuminate/database": "~5.0",
        "alexgarrett/violin": "2.*",
        "ircmaxell/random-lib": "~1.1"
    }
}

Can someone explain me why I'm getting this strange bad situation? Thanks in advance.


回答1:


Have a look at your composer.lock to see which version of illuminate/database got installed. The later ones are not compatible with PHP 5.6.30, but require PHP 7. You could try to enforce that version constraint through "illuminate/database": "~5.4.0"



来源:https://stackoverflow.com/questions/49204674/parse-error-when-run-illuminate-database-capsule-with-booteloquent-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!