dsavz66262 2018-09-07 07:47
浏览 61
已采纳

如果变量为空,则禁用按钮

So I have this forelse that displays all the variants, now what I want to happen is that, if there is no variant. the submit button will be disabled.

                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th class="col-sm-5">Name</th>
                                    <th class="col-sm-1">Default?</th>
                                    <th class="col-sm-2 text-right">Retail Price</th>
                                    <th class="col-sm-2 text-right">Quantity</th>
                                    <th class="col-sm-2"></th>
                                </tr>
                            </thead>
                            <tbody>
                            @forelse ($product->variants as $index => $variant)
                                <tr>
                                    <td>{{ $variant->name }}</td>
                                    <td>{{ $variant->is_default ? 'Yes' : 'No' }}</td>
                                    <td class="text-right">{{ number_format($variant->retail_price, 2) }} {{ $variant->price_currency }}</td>
                                    <td class="text-right">{{ number_format($variant->quantity, 0) }}</td>
                                    <td><a href="{{ route('developer.variants.edit', [$store->slug, $product, $variant]) }}" class="btn btn-xs btn-default pull-right">Edit</a></td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="5">No variants found</td>
                                    <?php $varbutton = 'disabled';?>
                                </tr>
                            @endforelse
                            </tbody>
                        </table>

here is the button

<div class="panel-footer">
  <button class="btn btn-default" type="submit"<?php $varbutton; ?>>Update Store</button>
</div>

Is it possible using php and html in the blade alone or do I have to do it in the controller?

  • 写回答

1条回答 默认 最新

  • douzhenqun1271 2018-09-07 07:52
    关注

    You should be using blade in your button:

    <div class="panel-footer">
      <button class="btn btn-default" type="submit" {{ $varbutton }}>Update Store</button>
    </div>
    

    Also please note that there needs to be a space after "submit".

    Or, if you don't want that space when the button is not disabled, use:

    <?php $varbutton = ' disabled';?>
    <div class="panel-footer">
      <button class="btn btn-default" type="submit"{{ $varbutton }}>Update Store</button>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集