gpt4 book ai didi

php - 未选中 Laravel Blade 复选框

转载 作者:可可西里 更新时间:2023-11-01 00:39:16 25 4
gpt4 key购买 nike

我正在将变量从 Controller 传递到 Blade 中。这是我来自 Controller 的代码:

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

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

@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

现在我希望如果变量值与常量匹配,则正确的复选框将被选中。下面是 Blade 文件中的代码,用于从一堆复选框中选中复选框。

<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

关于php - 未选中 Laravel Blade 复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50921665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com