问题描述
我在一个项目的根文件夹的控制台中写了 PHP artisan migrate:fresh --seed
,当我运行这个命令时,它需要将近 1 分钟然后它返回 \
在 PackageServiceProvider.PHP 第 14 行:
语法错误,意外的“包”(T_STRING),需要函数(T_FUNCTION)或常量(T_CONST)
PackageServiceProvider.PHP:
namespace Spatie\LaravelPackagetools;
use Carbon\Carbon;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use ReflectionClass;
use Spatie\LaravelPackagetools\Exceptions\InvalidPackage;
abstract class PackageServiceProvider extends ServiceProvider
{
protected Package $package; /* line 14 */
abstract public function configurePackage(Package $package): void;
public function register()
{
$this->registeringPackage();
$this->package = new Package();
$this->package->setBasePath($this->getPackageBaseDir());
$this->configurePackage($this->package);
if (empty($this->package->name)) {
throw InvalidPackage::nameIsrequired();
}
foreach($this->package->configFileNames as $configFileName) {
$this->mergeConfigFrom($this->package->basePath("/../config/{$configFileName}.PHP"),$configFileName);
}
$this->packageRegistered();
return $this;
}
.
.
.
.
}
项目作者的PHP版本:7.4.19
我的 PHP 版本:7.3.27
我是 laravel 的菜鸟,所以如果我必须提供有关该问题的更多信息,请告诉我。 \
编辑
更新PHP版本到7.4.21后
我写了命令,它返回了
C:\xampp\htdocs\Business-Manager>PHP artisan migrate:fresh --seed
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> y
Illuminate\Database\QueryException
sqlSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (sql: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
at C:\xampp\htdocs\Business-Manager\vendor\laravel\framework\src\Illuminate\Database\Connection.PHP:692
688▕ // If an exception occurs when attempting to run a query,we'll format the error
689▕ // message to include the bindings with sql,which will make this exception a
690▕ // lot more helpful to the developer instead of just the database's errors.
691▕ catch (Exception $e) {
➜ 692▕ throw new QueryException(
693▕ $query,$this->prepareBindings($bindings),$e
694▕ );
695▕ }
696▕
1 C:\xampp\htdocs\Business-Manager\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDO\Exception.PHP:18
Doctrine\DBAL\Driver\PDO\Exception::("sqlSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)")
2 C:\xampp\htdocs\Business-Manager\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.PHP:43
Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException))
我的 MysqL 帐户: enter image description here
解决方法
您的问题是 protected Package $package;
是 PHP 7.4
,它应该像 protected $package;
。
正如您在 source code 中看到的,它需要 php ^7.4
或 ^8.0
,因此您必须将 PHP 更改为其中之一。
This is another 可以查看您正在下载的 Composer 包的地方,以查看有关它的更多信息...
,在顶部导入合适的类。
use Facade\Ignition\Support\Packagist\Package;