Daveman
Daveman

Reputation: 1095

Laravel 5 - Use Auth::check() in view

I want to show a logout-button inside of my view if the user is logged in.

I've tried this:

@if( Auth::check() )
    <li><a href="{{url('/')/auth/logout}}">Logout</a></li>
@endif

But I'm getting this error-message:

Use of undefined constant auth - assumed 'auth'

What am I doing wrong?

Upvotes: 0

Views: 1733

Answers (1)

Joel Hinz
Joel Hinz

Reputation: 25374

The problem is not in the Auth::check(), but rather in this code:

{{url('/')/auth/logout}}

which translates into this php code:

<?php echo url('/')/auth/logout ?>

As you can see, php thinks that /auth/logout is php code and tries to execute it as such - but of course, it can't.

What you want is probably something like this:

{{ url('/') }}/auth/logout

or

{{ url('/auth/logout') }}

... although of course, it depends on what you're trying to link to. :)

Upvotes: 1

Related Questions