【发布时间】:2021-09-25 19:29:36
【问题描述】:
我在项目根文件夹的控制台写php artisan migrate:fresh --seed,当我运行这个命令时,大约需要1分钟然后它返回\
在 PackageServiceProvider.php 第 14 行:
语法错误、意外的“包”(T_STRING)、期望函数 (T_FUNCTION) 或 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
【问题讨论】:
-
更新你的php版本到7.4+
-
@OMIShah 你能再检查一下这个问题吗
-
是MySQL用户名密码访问问题。您提供了错误的 MySQL 用户名或密码
-
100% 正确,在 .env 文件中也一样
-
Lmao,您已在 .environment 文件中将 forge 设置为用户名,但您的 MySQL 表中有一个用户名为 root 的用户!
标签: laravel laravel-artisan artisan-migrate