在控制台中执行 php artisan migrate seed 时出错

error when executing php artisan migrate seed in console

我在一个项目的根文件夹的控制台写php artisan migrate:fresh --seed,当我运行这个命令时,它需要将近1分钟然后它returns \

在 PackageServiceProvider.php 第 14 行:

syntax error, unexpected 'Package' (T_STRING), expecting function (T_FUNCTION) or const (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 包的地方,查看更多信息...

在顶部导入合适的class。

use Facade\Ignition\Support\Packagist\Package;