Prince Asamoah
Prince Asamoah

Reputation: 135

How to use if statement to compare value from a database in laravel?

I want to change the look of a label when the result from the database is equal a certain word. for instance. In my application when full payment is made, i want to change the appearance using bootstrap class. similarly, i want to change it when the user is owing.

This is what i did but it seem not to be working.

This is the error am getting syntax error, unexpected '<'

@if( {{$data -> status}} == "Full Payment"  )

<label class="btn btn-primary">{{$data -> status}}</label>

@endif

@if( {{$data -> status}} == "owing"  )

<label class="btn btn-danger">{{$data -> status}}</label>

@endif

how do i change the appearance depending on the results from the database

Upvotes: 0

Views: 1028

Answers (3)

Alem Tuzlak
Alem Tuzlak

Reputation: 36

What i would recommend doing if those are the only 2 possible outcomes is:

<label class="btn {{ $data->status == 'Full Payment' ? 'btn-primary' : 'btn-danger' }}">{{$data -> status}}</label>

Upvotes: 1

A.A Noman
A.A Noman

Reputation: 5270

You have to use like this

@if($data -> status == "Full Payment")

And

@if($data -> status == "owing")

Upvotes: 0

zlatan
zlatan

Reputation: 3951

You don't need {{}} braces when you use blade tags (@), since PHP is already parsed inside them. This way when your code gets to first brackets ( {{ ) it renders them as <?php, and you get the syntax error. Change your conditions to this:

@if($data->status == "Full Payment"  )
   <label class="btn btn-primary">{{$data->status}}</label>
@endif

@if($data->status == "owing"  )
   <label class="btn btn-danger">{{$data->status}}</label>
@endif

Upvotes: 1

Related Questions