user3386779
user3386779

Reputation: 7205

if else condition in blade file (laravel 5.3)

I want to check if/else condition in my blade file. I want to check the condition $user->status =='waiting' as the code given below. Output returns correctly as I expected. But along with my output I caught curly braces {} printed. I want to remove curly braces in result. Is there anything wrong in my if condition ?

@if($user->status =='waiting')
         {
           <td><a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">Approve/Reject<a></td>
         }
         @else{
           <td>{{ $user->status }}</td>
         }
         @endif

Upvotes: 58

Views: 380115

Answers (4)

Cengkuru Michael
Cengkuru Michael

Reputation: 4790

I think you are putting one too many curly brackets. Try this

 @if($user->status=='waiting')
            <td><a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">Approve/Reject</a> </td>
            @else
            <td>{{ $user->status }}</td>
        @endif

Upvotes: 9

Muhammad Zohaib Yunis
Muhammad Zohaib Yunis

Reputation: 536

If wants to assign value on basis of if else inside blade.

@if($shipping_fee >= 1)
  @php
    $shipping_fee = $any_variable1
  @endphp
@else
  @php
    $shipping_fee = $any_variable2
  @endphp
@endif

Upvotes: 2

Pejman Zeynalkheyri
Pejman Zeynalkheyri

Reputation: 4812

You don't have to use braces in blade conditions, so your code would be like this:

@if($user->status =='waiting')
    <td>
        <a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">
            Approve/Reject
        <a>
    </td>
@else
    <td>
        {{ $user->status }}
    </td>
@endif

Upvotes: 3

Rakesh Sojitra
Rakesh Sojitra

Reputation: 3658

No curly braces required you can directly write

@if($user->status =='waiting')         
      <td><a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">Approve/Reject<a></td>         
@else
      <td>{{ $user->status }}</td>        
@endif

Upvotes: 131

Related Questions