Phil Nind
Phil Nind

Reputation: 341

Stripe + Laravel - Call to a member function subscribed() on null

This is very strange my subscription site was working yesterday but today it is giving me the error - Call to a member function subscribed() on null

I have checked my edited code in the last day and nothing obvious stands out.

My code is...

@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

and the controller code is

public function home()
{
    $user = Auth::user();

    return view('home')->with(['user' => $user,]);
}

Upvotes: 1

Views: 2458

Answers (1)

MozzieMD
MozzieMD

Reputation: 355

You need to check Auth::check() before using Auth::user()

Something like this:

@if (Auth::check() && !$user->subscribed())

Upvotes: 4

Related Questions