Search code examples
phplaravellaravel-8intelephense

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


Solution

  • Use notification facade instead of method.

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

    Replace with this:

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