0

I am using laravel 5.4, there is an error in the code below,
but there is no error when using laravel 5.3,
why is it?

controller:

public function index()
{
    $user=\Auth::user();
    $articles=$user->articles;

    return view('index',  compact('user','articles'));
}

view:

{{ $articles->count() }}

error:

Call to a member function count() on null

what should I do?

2 Answers 2

1

Laravel 5.4 you should try:

{{ count($articles) }}
Sign up to request clarification or add additional context in comments.

Comments

0

Change it to count($articles). ->count() on a null value produces indeed an error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.