dongtui9168 2018-12-11 22:18
浏览 23

如何从选项php中显示一些值

In database, i have 4 values for pricing plan: - Star (plan_id = 1) - Moon (plan_id = 2) - Sun (plan_id = 3) - Galaxy (plan_id = 4)

On signup page, I only want to display plan_id 2 & 3. Is it possible?

My current code for the pricing plan option as follow:

               <div class="form-group">
                    <label for="plan_id">Plan</label>
                    <select class="form-control select2" name="plan_id" id="plan_id" required>
                       <option value="" disabled selected>Choose a plan</option>
                       @foreach($plan as $plans)
                          <option value="{{ $plans->id }}">{{ $plans->plan_name }}</option>
                       @endforeach
                    </select>
                 </div>

Will appreciate any help you can. Thank you

  • 写回答

1条回答 默认 最新

  • dsxmwin86342 2018-12-11 22:31
    关注

    You'll want to keep the data manipulate to a minimum in your template so ideally you'll handle the data in your controller and pass it to the template. Is the code above shared by the signup page and other pages? If not, then you can filter the data in the controller to only return plan_id 2 and 3 and then pass that to the template.

    in the controller:

    $plans = [
        ['id' => 1, 'plan_name' => 'Star'],
        ['id' => 2, 'plan_name' => 'Moon'],
        ['id' => 3, 'plan_name' => 'Sun'],
        ['id' => 4, 'plan_name' => 'Galaxy'],
    ];
    
    $filtered = array_filter($plans, function($plan) {
        return in_array($plan, [2, 3]);
    });
    

    Then you can pass $filtered to your template.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题