我将变量从控制器传递到刀片中。这是我来自控制器的代码:
$offerConditionsData = Offercondition::where('offerId', $id)->where('deleted', '0')->get();
return view('Administrator.offers.add', $data);
我在刀片文件的顶部定义了一个变量:
@if(isset($offerConditionsData))
@foreach ($offerConditionsData as $offerConditions)
@php $selectedCondCheckbox = $offerConditions->keyword;
@endphp
@endforeach
@endif
如果我回显$ selectedCondCheckbox,那么我找到了以下内容:
customer_get_discounts_and_special_offers_on_certain_product_or_categories
现在我希望如果变量值与常量匹配,则会选中正确的复选框。以下是刀片文件中的代码,用于选中一系列复选框中的复选框。
<input type="radio" name="condition_tab" value="1" class="flat-red" style="position: absolute; opacity: 0;" @php if(isset($selectedCondCheckbox) == 'customer_get_discounts_and_special_offers_on_certain_product_or_categories') { echo "checked=checked"; } else { echo ""; } @endphp>
<input type="radio" name="condition_tab" value="2" class="flat-red" style="position: absolute; opacity: 0;" @php if(isset($selectedCondCheckbox) == 'discount_on_total_amount_of_shipping') { echo "checked=checked"; } else { echo ""; } @endphp>
但是,我看到第二个复选框已被选中。它应该检查第一个复选框作为php变量的值,与常量匹配。
答案 0 :(得分:3)
你的if条件确实存在一些错误
单独尝试条件
#include <stdio.h>
#include <ctype.h>
char c;
char num (char c);
int main () {
int sum;
printf("Enter a word:");
c=0;
while (c=getchar() != '\n') {
c=toupper(c);
sum+=c;
}
printf("Scrabble value : %d",sum);
return(0);
}
char num (char c) {
if (c=='A'||c=='E'||c=='I'||c=='L'||c=='N'||c=='O'||c=='R'||c=='S'||c=='T'||c=='U') c=1;
if (c=='D'||c=='G') c=2;
if (c=='B'||c=='C'||c=='M'||c=='P') c=3;
if (c=='F'||c=='H'||c=='V'||c=='W'||c=='Y') c=4;
if (c=='K') c=5;
if (c=='J'||c=='X') c=8;
if (c=='Q'||c=='Z') c=10;
return(c);
}
答案 1 :(得分:2)
尝试使用此代码
<input type="radio" name="condition_tab" value="1" class="flat-red" style="position: absolute; opacity: 0;" {{ isset($selectedCondCheckbox) ? $selectedCondCheckbox == 'customer_get_discounts_and_special_offers_on_certain_product_or_categories' ? 'checked=checked' :'' :'' }} >
<input type="radio" name="condition_tab" value="2" class="flat-red" style="position: absolute; opacity: 0;" {{ isset($selectedCondCheckbox) ? $selectedCondCheckbox == 'discount_on_total_amount_of_shipping' ? 'checked=checked' :'' :'' }}>