【问题标题】:Undefined method 'notify'. intelephense(1013)未定义的方法“通知”。智能手机(1013)
【发布时间】:2021-08-13 08:29:00
【问题描述】:

我有这样的代码和平:

auth()->user()->notify(new TestNotification($oneParam, $twoParam));

我的auth()->user()返回用户登录喜欢:

App\Models\User\User {#1094 ▼
  +timestamps: false
  #fillable: array:8 [▶]
  #hidden: array:1 [▶]
  #appends: array:1 [▶]
  #connection: "mysql"
  #table: "users"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:13 [▶]
  #original: array:13 [▶]
  #changes: []
  #casts: []
  #classCastCache: []
  #dates: []
  #dateFormat: null
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  #visible: []
  #guarded: array:1 [▶]
  #rememberTokenName: "remember_token"
  #accessToken: Laravel\Passport\Token {#1055 ▶}
}

我在 User Model 中有 use Notifiable; 特征和 use Illuminate\Notifications\Notifiable; 导入。

VSC 扩展:PHP Intelephense v1.7.1 PHP 7.4.9 Laravel 框架 8.52.0

【问题讨论】:

    标签: php laravel laravel-8 intelephense


    【解决方案1】:

    使用通知外观而不是方法。

    auth()->user()->notify(new TestNotification($oneParam, $twoParam));
    

    替换为:

    Notification::send(auth()->user(), new TestNotification($oneParam, $twoParam));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      相关资源
      最近更新 更多