Unyxos Unyxos - 7 months ago 52
PHP Question

Blade if() condition error

I'm trying to write a if() condition with Blade, I have this :

@foreach($users as $user)
<td><a href="delmember/{{$user->id}}">Supprimer le membre</a></td>
@if({{$user->admin}} == 0)
<td><a href="makeadmin/{{$user->id}}">Passer l'utilisateur Admin</a></td>
<td><a href="noadmin/{{$user->id}}">Retirer l'admin à l'utilisateur</a></td>

I want to check if the user is admin or not (column in my users table) but the if returns me 3 errors :
first one : if(^here{{$user->admin}} == 0) -> Expected : condition

Seconde one : if({{$user->admin**^here**}} == 0) -> Expected : semicolon

Third one : if({{$user->admin}}^here == 0) -> Expected : Statement

I searched for a while how to fix it but I don't find, maybe someone could help me.

Thank you :)


Inside blade tags, you don't need to add another tag. You are currently trying to add {{ }} tag inside the @if() tag. Try to think like this: {{ /* php code */ }} and @if(/* php code */).

So, to fix your problem, you simply write: @if($user->admin == 0) and that should be it.