调用未定义的方法Illuminate \ Auth \ GenericUser :: hasFriendRequestPending()

时间:2017-03-27 12:26:25

标签: php laravel laravel-5.3

我有这个错误我使用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,
],

1 个答案:

答案 0 :(得分:0)

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

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

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

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