php – Laravel Blade复选框未选中
作者:互联网
我将变量从控制器传递到刀片中.这是我的控制器代码:
$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变量的值,与常量匹配.
解决方法:
你的if条件肯定存在一些错误
分别尝试条件
@php if(isset($selectedCondCheckbox)) {
if($selectedCondCheckbox =='discount_on_total_amount_of_shipping')
{ echo "checked=checked"; }}@endphp
标签:laravel-blade,php,laravel 来源: https://codeday.me/bug/20190828/1747043.html