【问题标题】:Call to undefined method Illuminate\Auth\GenericUser::hasFriendRequestPending()调用未定义的方法 Illuminate\Auth\GenericUser::hasFriendRequestPending()
【发布时间】:2017-03-27 21:42:50
【问题描述】:

我有这个错误我使用 laravel 5.3 调用未定义的方法 Illuminate\Auth\GenericUser::hasFriendRequestPending() 任何人都可以帮助我吗?!!

用户模型

     public function friendsOfMine()
      {
       return $this->belongsToMany('App\User', 'friends' , 'user_id' , 'friend_id');
      }
      public function friendOf(){
       return $this->belongsToMany('App\User', 'friends' , 'friend_id' , 'user_id' );
      }
     public function friendRequestsPending()
      {
       return $this->friendOf()->wherePivot('accepted' , false)->get();
      }
     public function hasFriendRequestPending(User $user)
     {
     return (bool) $this->friendRequestsPending()->where('id' , $user->id)->count();
     }

在视图中

                    <h4>Friend Requests</h4>
                    @if (Auth::user()->hasFriendRequestPending($user))
                          <p>Waiting For {{$user->username}} To Accept Your Request. </p>

                    @endif

auth.php

      'providers' => [
        'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
],

【问题讨论】:

  • 我认为你的问题有一点错别字。您在错误消息中写了hasFriendRequestsPending,而您的其余代码是hasFriendRequestPending,所以这让我很困惑,仅此而已。
  • 这是我的错误调用未定义的方法 Illuminate\Auth\GenericUser::hasFriendRequestsPending()
  • 我编辑了我的答案。

标签: php laravel laravel-5.3


【解决方案1】:

您的错误是方法hasFriendRequestsPending() 未定义。 但是你的函数名其实是hasFriendRequestPending()

尝试找到您呼叫hasFriendRequestsPending()的位置并将其更改为hasFriendRequestPending()

您还可以检查您的 config/auth.php 中是否设置了正确的提供程序:

'providers' => [
    'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
    ],

【讨论】:

  • 你能解释一下吗?
  • 调用未定义的方法 Illuminate\Auth\GenericUser::hasFriendRequestPending()
  • 编辑了一个新的潜在客户,你能检查一下吗?
  • 那我真的不知道,抱歉。请使用更多信息、更多代码、更多配置编辑您的初始问题。
猜你喜欢
  • 2020-04-07
  • 2017-11-06
  • 1970-01-01
  • 1970-01-01
  • 2020-01-24
  • 2016-06-25
  • 2017-07-14
  • 2020-07-06
  • 2015-09-23
相关资源
最近更新 更多