【问题标题】:syntax error, unexpected ')' in laravel 8. \vendor\laravel\framework\src\Illuminate\Bus\BusServiceProvider.php:51 [closed]语法错误,在 laravel 8 中出现意外的 ')'。\vendor\laravel\framework\src\Illuminate\Bus\BusServiceProvider.php:51 [关闭]
【发布时间】:2021-01-13 16:46:30
【问题描述】:

我正在尝试从 laravel 8 应用发送通知。” 当我点击 URL 时,我得到了错误。语法错误,意外的 ')' 在路由文件中:

Route::get('/twitter', function (){
    Notification::route(TwitterChannel::class,'')->notify(new TestNotification());
});

在通知文件中

public function via($notifiable)  {
    return [TwitterChannel::class];
}
public function toTwitter($notifiable)
{
    return new TwitterStatusUpdate('Laravel notifications are awesome!');
}

在 composer.json 文件中

"require": {
    "php": "^7.3",
    "fideloper/proxy": "^4.2",
    "fruitcake/laravel-cors": "^2.0",
    "guzzlehttp/guzzle": "^7.0.1",
    "laravel-notification-channels/twitter": "^5.0",
    "laravel/framework": "^8.0",
    "laravel/tinker": "^2.0"
},

错误页面截图是: The error page screenshot

【问题讨论】:

  • 您使用的 PHP 版本错误
  • 首先使用 php -v 检查你的 php 版本。这不会一直打印准确的 php 版本。这就是为什么你应该使用 在代码中

标签: php laravel laravel-8


【解决方案1】:

Laravel 8 需要 PHP >= 7.3。您使用的版本低于该版本,因此它不支持函数调用中的尾随逗号。

错误是您使用错误版本的证据。

PHP.net Manual - 7.3 Features - Trailing Commas are allowed in Calls

【讨论】:

  • 我的 PHP 版本是 PHP 7.4.10 (cli) (built: Sep 1 2020 16:52:21) (NTS Visual C++ 2017 x64) 版权所有 (c) The PHP Group Zend Engine v3.4.0 , 版权所有 (c) Zend Technologies
  • 您使用了错误的版本...您的系统上有多个版本(CLI 正在使用 7.4)...再次证明错误
【解决方案2】:

第 50 行末尾似乎是逗号问题。

谢谢

【讨论】:

  • PHP >= 7.3 支持此功能
  • 请提供更多信息 - 答案不仅应检查错误,还应提供解决方法
猜你喜欢
  • 2018-05-13
  • 1970-01-01
  • 2023-03-05
  • 2022-11-28
  • 2019-10-28
  • 2022-06-29
  • 2020-11-01
  • 2021-09-02
  • 2021-06-28
相关资源
最近更新 更多