php - Undefined method 'notify'. intelephense(1013)
问题描述
I have this peace of code:
auth()->user()->notify(new TestNotification($oneParam, $twoParam));
My auth()->user()
return the user logged in like:
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 ▶}
}
And I have in User Model
the use Notifiable;
trait and use Illuminate\Notifications\Notifiable;
import.
VSC extension: PHP Intelephense v1.7.1 PHP 7.4.9 Laravel Framework 8.52.0
解决方案
Use notification facade instead of method.
auth()->user()->notify(new TestNotification($oneParam, $twoParam));
Replace with this:
Notification::send(auth()->user(), new TestNotification($oneParam, $twoParam));
推荐阅读
- flutter - 使用自定义 ChangeNotifier 初始化riverpod Provider
- postgresql - PostgreSQL中数据类型的大写/小写是否有最佳实践
- variables - Jenkins 变量不能在管道中使用 sed 命令
- python - 但是,if 语句和 else 都打印出来,它们都没有获取 url 数据库
- python - Xpath:选择正文中的所有文本,除非在页眉、导航或页脚子部分中
- javascript - Vue.js 组件:作为对象的道具不适用于 x-template
- regex - XSD 中模式匹配的正则表达式
- javascript - 如何从主要角度包导出默认导出?
- java - 使用 GSON 反序列化泛型类型时遇到问题
- node.js - 如何使用 react.js 前端发送电子邮件?