未选中 Laravel Blade 复选框

Nil*_*ara 5 php laravel laravel-blade

我正在将变量从控制器传递到刀片中。这是我的控制器代码:

$offerConditionsData = Offercondition::where('offerId', $id)->where('deleted', '0')->get();
return view('Administrator.offers.add', $data);
Run Code Online (Sandbox Code Playgroud)

我在刀片文件的顶部定义了一个变量:

@if(isset($offerConditionsData))
@foreach ($offerConditionsData as $offerConditions)
@php $selectedCondCheckbox = $offerConditions->keyword;
@endphp
@endforeach
@endif
Run Code Online (Sandbox Code Playgroud)

如果我回显 $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>
Run Code Online (Sandbox Code Playgroud)

但是,我看到第二个复选框被选中。它应该检查第一个复选框作为 php 变量的值,与常量匹配。

Ath*_*Raj 4

你的 if 条件肯定有问题

分别尝试条件

       @php if(isset($selectedCondCheckbox)) { 
            if($selectedCondCheckbox =='discount_on_total_amount_of_shipping') 
            { echo "checked=checked"; }}@endphp
Run Code Online (Sandbox Code Playgroud)