在 null 上调用成员函数 checkLearning()(视图:
Call to a member function checkLearning() on null (View:
你好,我使用了这个方法,但在视图上不起作用
@if(! auth()->user()->checkLearning($course))
<form action="/series/payment" method="post">
{{csrf_field()}}
<input type="hidden" name="course_id" value="{{$course->id}}">
<button type="submit" class="btn-tohid">خریداری این دوره</button>
</form>
@else
<a href="#">به این دوره دسترسی دارید</a>
@endif
和我在用户中的模型
public function checkLearning($course)
{
return !! Learning::where('user_id' , $this->id)->where('course_id' , $course->id)->first();
}
从我在这里看到的情况来看,您正试图从未登录的用户那里获取 checkLearning()
,因此您收到了错误消息。 auth()->user()
方法returnsnull
,null
没有checkLearning()
方法。不确定你在这种情况下要检查什么,但是如果你想检查登录用户 has/doesn 在 Learning
模型中是否有一些记录,你需要将你的条件更改为此:
@if(auth()->user() && !auth()->user()->checkLearning($course))
//First check if user is logged in, then check if he has/doesn't have records
@else
//Do something else
@endif
此外,我不确定 !!
在您的 checkLearning()
方法中代表什么,您能提供更多信息吗?
你好,我使用了这个方法,但在视图上不起作用
@if(! auth()->user()->checkLearning($course))
<form action="/series/payment" method="post">
{{csrf_field()}}
<input type="hidden" name="course_id" value="{{$course->id}}">
<button type="submit" class="btn-tohid">خریداری این دوره</button>
</form>
@else
<a href="#">به این دوره دسترسی دارید</a>
@endif
和我在用户中的模型
public function checkLearning($course)
{
return !! Learning::where('user_id' , $this->id)->where('course_id' , $course->id)->first();
}
从我在这里看到的情况来看,您正试图从未登录的用户那里获取 checkLearning()
,因此您收到了错误消息。 auth()->user()
方法returnsnull
,null
没有checkLearning()
方法。不确定你在这种情况下要检查什么,但是如果你想检查登录用户 has/doesn 在 Learning
模型中是否有一些记录,你需要将你的条件更改为此:
@if(auth()->user() && !auth()->user()->checkLearning($course))
//First check if user is logged in, then check if he has/doesn't have records
@else
//Do something else
@endif
此外,我不确定 !!
在您的 checkLearning()
方法中代表什么,您能提供更多信息吗?