Stripe + Laravel - 在 null 上调用成员函数 subscribed()
Stripe + Laravel - Call to a member function subscribed() on null
这很奇怪,我的订阅网站昨天还在运行,但今天却出现错误 - 在 null 上调用成员函数 subscribed()
我检查了我在最后一天编辑的代码,没有什么明显的问题。
我的代码是...
@if (!$user->subscribed())
<h1>You are not currently subscribed!</h1>
<a href="plans" class="btn btn-green btn-lg btn-large">SUBSCRIBE</a>
@elseif(Auth::guest())
<h1>You need to be a member to view todays tips!</h1>
<a href="login" class="btn btn-green btn-lg btn-large">LOGIN</a>
<a href="register" class="btn btn-blue btn-lg btn-large">REGISTER</a>
@else
@forelse($todaystips as $tip)
<h3>{{ $tip->league }}</h3>
<h2>{{ $tip->home_team }} V {{ $tip->away_team }}</h2>
<h3><b>{{ $tip->tip }}</b> {{ $tip->odds }}</h3>
@empty<h1>There are no tips today! Check back tomorrow!</h1>
@endforelse
@endif
控制器代码为
public function home()
{
$user = Auth::user();
return view('home')->with(['user' => $user,]);
}
使用前需要检查Auth::check()
Auth::user()
像这样:
@if (Auth::check() && !$user->subscribed())
这很奇怪,我的订阅网站昨天还在运行,但今天却出现错误 - 在 null 上调用成员函数 subscribed()
我检查了我在最后一天编辑的代码,没有什么明显的问题。
我的代码是...
@if (!$user->subscribed())
<h1>You are not currently subscribed!</h1>
<a href="plans" class="btn btn-green btn-lg btn-large">SUBSCRIBE</a>
@elseif(Auth::guest())
<h1>You need to be a member to view todays tips!</h1>
<a href="login" class="btn btn-green btn-lg btn-large">LOGIN</a>
<a href="register" class="btn btn-blue btn-lg btn-large">REGISTER</a>
@else
@forelse($todaystips as $tip)
<h3>{{ $tip->league }}</h3>
<h2>{{ $tip->home_team }} V {{ $tip->away_team }}</h2>
<h3><b>{{ $tip->tip }}</b> {{ $tip->odds }}</h3>
@empty<h1>There are no tips today! Check back tomorrow!</h1>
@endforelse
@endif
控制器代码为
public function home()
{
$user = Auth::user();
return view('home')->with(['user' => $user,]);
}
使用前需要检查Auth::check()
Auth::user()
像这样:
@if (Auth::check() && !$user->subscribed())