Using if condition to display data in Blade - laravel

How print value in this code:
<li class="price-val">{{ $value->price ? '$value->price € month<span class="price-fea-ct">*VAT Included</span>':'$value->price € month' }}</li>
$value->price variable is have 0 & 9 value respectively.but it does print value.print $value->price just.

Something like this should work
<li class="price-val">
#if ($value->price)
{{{ $value->price }}} € month<span class="price-fea-ct">*VAT Included</span>
#else
{{{ $value->price }}} € month
#endif
</li>
However for me the condition doesn't make sense - if price is 0 you will display 0 / month and it does not seem to be logical

You have syntax errors, try this:
<li class="price-val">
{{
$value->price ?
$value->price . '€ month <span class="price-fea-ct">*VAT Included</span>' :
$value->price . '€ month'
}}
</li>

Related

Laravel having space output issue in blade file

I have Laravel code in Blade like this :
<span id="pk_dens" name="pk_dens" class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif">
{{$productpages->pk_dens}}%
</span>
So in class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif"
it will add space in class like text- danger and text- success so class not apply
so how can I avoid that spce in if else condition ?
Use ternary operator
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">
{{$productpages->pk_dens}}%
</span>
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
I think you are missing here is ? in ternary syntax and to remove space just remove all white spaces from the span tag and make it in just one line.
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">{{$productpages->pk_dens}}%</span>

Laravel total foreach index number

I want to total all the rows to loop, what do I do?
example :
index 0
ixdex 1
I want this ซ
index 2
My code :
#if(isset($unread[$messages_conversation_teachers->conversation_id]))
#foreach($unread[$messages_conversation_teachers->conversation_id] as $_index =>$unreads)
{{$_index}}
#endforeach
#endif
try this $loop->iteration it start from 1 not 0
#if(isset($unread[$messages_conversation_teachers->conversation_id]))
#foreach($unread[$messages_conversation_teachers->conversation_id] as $_index =>$unreads)
{{ $loop->iteration }}
#endforeach
#endif
ref link https://laravel.com/docs/8.x/blade#the-loop-variable

How to update the text based on the response value in quasar?

I have a q-table where I get a response from API. In one of the entries, it gives the value of the flag as 0 or 1 which I need to update it as Yes or No.
How can I do this?
I am using q-badge to change the bg color and highlight it but unable to update the text.
<template v-slot:body-cell-processed="props">
<q-td :props="props" >
<q-badge style="background-color:white" :class="props.row.processed==0?'bg-red':'text-black'">
{{ props.row.processed }}
</q-badge>
</q-td>
</template>
I have tries this and it's working fine.
<q-td key="processed" :props="props">
<q-badge style="background-color:white" :class="props.row.processed==0?'bg-red text-white text-weight-bolder':'bg-blue text-black'">
{{ props.row.processed }}
</q-badge>
</q-td>
Codepen - https://codepen.io/Pratik__007/pen/PoqzzLx?editable=true&editors=101

laravel Blade is their a neat solution to : Trying to get property of non-object

I have thins line of code
{{($user->company_privileges->level < 3 ? '' : ' disabled') }}
In my menu file
but when a user doesn't have a company I get the error
Trying to get property of non-object
Is their a neat way of dealing with this in one line?
Something like this comes to mind
{{ ($user->company_privileges === null) : '' ? ($user->company_privileges->level < 3 ? '' : ' disabled') ) }}
as the second if statement is only ran if the user has a company
I have the statement inside a tag aswell
<a class="{{($user->company_privileges->level < 3 ? '' : ' disabled') }}">
Why not something like
<a class="{{($user->company_privileges && $user->company_privileges->level < 3 ? '' : ' disabled') }}">
Essentially, what you need here is to know that null == false for bool comparison. Check out the PHP type comparisons table

Get link inside several p elements using xpath

I have the following code (as part of a page):
<div class="examples">
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
<p class="update">Day 1 : exampletext</p>
</div>
I'm trying to get the link (href and title) using xpath. There are several "update" p class elements on the same page, i need them all. I'm not really interested for the "Day 1 : " text (or whatever day gets there).
Is this possible?
Thanks.
One possible xpath :
//div[#class='examples']/p[#class='update']/a
Output :
'exampletext'
'exampletext'
'exampletext'
'exampletext'
'exampletext'
'exampletext'

Resources