【问题标题】:error when i run php artisan migrate command on line 51当我在第 51 行运行 php artisan migrate 命令时出错
【发布时间】:2023-03-13 09:16:01
【问题描述】:

当我在终端运行 php artisan migrate 命令时,我只剩下这个了。

   ParseError 

  syntax error, unexpected ')'

  at C:\laragon\www\testnum2\vendor\laravel\framework\src\Illuminate\Bus\BusServiceProvider.php:51
     47▕             return new DatabaseBatchRepository(  
     48▕                 $app->make(BatchFactory::class), 
     49▕                 $app->make('db')->connection(config('queue.batching.database')),
     50▕                 config('queue.batching.table', 'job_batches'),
  ➜  51▕             );
     52▕         });
     53▕     }
     54▕
     55▕     /**

  1   C:\laragon\www\testnum2\vendor\composer\ClassLoader.php:322
      Composer\Autoload\includeFile("C:\laragon\www\testnum2\vendor\composer/../laravel/framework/src/Illuminate/Bus/BusServiceProvider.php")

  2   [internal]:0
      Composer\Autoload\ClassLoader::loadClass("Illuminate\Bus\BusServiceProvider")
PS C:\laragon\www\testnum2>

我不太确定是什么原因造成的,但这是导致错误的文件的代码。

<?php

namespace Illuminate\Bus;

use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract;
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;

class BusServiceProvider extends ServiceProvider implements DeferrableProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(Dispatcher::class, function ($app) {
            return new Dispatcher($app, function ($connection = null) use ($app) {
                return $app[QueueFactoryContract::class]->connection($connection);
            });
        });

        $this->registerBatchServices();

        $this->app->alias(
            Dispatcher::class, DispatcherContract::class
        );

        $this->app->alias(
            Dispatcher::class, QueueingDispatcherContract::class
        );
    }

    /**
     * Register the batch handling services.
     *
     * @return void
     */
    protected function registerBatchServices()
    {
        $this->app->singleton(BatchRepository::class, DatabaseBatchRepository::class);

        $this->app->singleton(DatabaseBatchRepository::class, function ($app) {
            return new DatabaseBatchRepository(
                $app->make(BatchFactory::class),
                $app->make('db')->connection(config('queue.batching.database')),
                config('queue.batching.table', 'job_batches'),
            );
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [
            Dispatcher::class,
            DispatcherContract::class,
            QueueingDispatcherContract::class,
            BatchRepository::class,
        ];
    }
}

我希望这足以获得帮助。 我还想提一下,我之前使用过 php artisan migrate,最近我不得不升级一些东西,比如 composer 和 phpmyadmin

【问题讨论】:

  • 你用的是什么php版本?
  • 很可能它在函数调用中的尾随逗号:config('queue.batching.table', 'job_batches'), 并且您有 php 7.2(或更早版本),尚不允许使用。

标签: php laravel-artisan laravel-8


【解决方案1】:

问题是您使用的 PHP 版本(低于 7.3)不支持函数调用中的尾随逗号。

请阅读:Trailing Commas are allowed in Calls

解决办法是切换到&gt; PHP 7.3

【讨论】:

  • 逗号是否有原因。当我删除逗号时它可以工作。所以只是为了确认这不会在未来造成问题,对吧?
  • 您不应该更改vendor 目录中的任何内容。因为一次更新可能会破坏您的整个站点,因为您的更改将不存在。我建议您使用 php7.3 或改用 laravel 7。
  • 当我运行 它显示为 PHP 7.4.11。我没有那么有经验,所以有可能我下载了错误的。官方网站上是php-7.4.11-Win32-vc15-x64.zip
  • @MuamarCollins 这很奇怪。如果您使用的是 php7.4,那么您不应该遇到这个问题。
  • 是的,你认为这可能是 phpmyadmin 或其他什么问题。我可能只是重新安装 laragon,然后我可能可以指出它到底是什么。在更新之前我没有这个问题。
【解决方案2】:

我的问题是我的 PHP

但是当我简单地在 phpinfo 文件中检查它时,它显示为 7.4.11。

@lagbox 帮我说:“你的系统上有不同的版本,CLI 和网络服务器可以有不同的配置”

老实说,我不确定该怎么做,但我决定从我的 PATH 中删除 PHP 7.2

  • 我希望它能够识别出我使用的是 7.4,令我惊讶的是它确实做到了。
  • 此外,我确信有更有效的方法可以做到这一点,但这是我选择的方式。

【讨论】:

    猜你喜欢
    • 2017-05-31
    • 2016-09-07
    • 2019-10-29
    • 1970-01-01
    • 2021-07-27
    • 2018-12-05
    • 2021-08-19
    • 1970-01-01
    • 2021-12-11
    相关资源
    最近更新 更多