Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

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

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 IlluminateDatabaseCapsuleManager 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...