Ryan B
Ryan B

Reputation: 108

Laravel IF statement throws back error

i want to write an IF statement in laravel which is something like this:

@if ({{ Auth::users->admin }} == 1)
    test
@else
    Test2
@endif

so i want to check the database to see if the admin is equal to 1 in the users table, but laravel throws back

Parse error: syntax error, unexpected '<'

How do i fix this?

Upvotes: 2

Views: 58

Answers (2)

Parth Vora
Parth Vora

Reputation: 4114

Try this:

@if (Auth::user()->admin == 1) 
  test 
@else 
  Test2 
@endif

Upvotes: -1

Robin Dirksen
Robin Dirksen

Reputation: 3422

You can use this if your view is visible for unauthenticated users:

@if(Auth::check() && Auth::user()->admin == 1)
    test
@else
    Test2
@endif

Otherwise you can simply use: @if(Auth::user()->admin == 1) test @else Test2 @endif

{{ }} will echo the output in the view. While @if(Auth::user()->admin == 1) make an if statement. if(Auth::user()->admin == 1).

Upvotes: 2

Related Questions