【发布时间】: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