如何在laravel中显示1个计划?

时间:2018-03-21 07:21:06

标签: php laravel

我有一个页面“存款”这里有计划是可用的“foreach” 现在我想在这里只显示3号计划。意思是3的平均计划。

<div class="row">
    @foreach($plan as $p)

    <div class="col-sm-4 text-center">
        <div class="panel panel-info panel-pricing">
            <div class="panel-heading">
                <h3 style="font-size: 28px;"><b>{{ $p->name }}</b></h3>
            </div>
            <div style="font-size: 18px;padding: 18px;" class="panel-body text-center">
                <p><strong>{{ $p->minimum }} {{ $basic->currency }} - {{ $p->maximum }} {{ $basic->currency }}</strong></p>
            </div>
            <ul style='font-size: 15px;' class="list-group text-center bold">
                <li class="list-group-item"><i class="fa fa-check"></i> Commission - {{ $p->percent }} <i class="fa fa-percent"></i> </li>
                <li class="list-group-item"><i class="fa fa-check"></i> Time - {{ $p->time }} times </li>
                <li class="list-group-item"><i class="fa fa-check"></i> Compound - <span class="aaaa">{{ $p->compound->name }}</span></li>
            </ul>
            <div class="panel-footer" style="overflow: hidden">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-info btn-block btn-icon icon-left delete_button"
                            data-toggle="modal" data-target="#DelModal"
                            data-id="{{ $p->id }}">
                        <i class="fa fa-send"></i> Invest Under This Package
                    </button>
                </div>
            </div>
        </div>
    </div>
    @endforeach
</div>

3 个答案:

答案 0 :(得分:2)

您只需从$plan集合中提取计划,在下面的案例中不需要循环

$p = $plan ->find(3);

答案 1 :(得分:0)

如果您想使用foreach并显示计划ID 3,请尝试以下操作:

        <div class="row">
     @foreach($plan as $p)
     @if($p == 3)

     <div class="col-sm-4 text-center">
      <div class="panel panel-info panel-pricing">
     <div class="panel-heading">
     <h3 style="font-size: 28px;"><b>{{ $p->name }}</b></h3>
                                            </div>
    <div style="font-size: 18px;padding: 18px;" class="panel-body text-center">
     <p><strong>{{ $p->minimum }} {{ $basic->currency }} - {{ $p->maximum }} {{ $basic->currency }}</strong></p>
                                            </div>
 <ul style='font-size: 15px;' class="list-group text-center bold">
    <li class="list-group-item"><i class="fa fa-check"></i> Commission - {{ $p->percent }} <i class="fa fa-percent"></i> </li>
                                                <li class="list-group-item"><i class="fa fa-check"></i> Time - {{ $p->time }} times </li>
                                                <li class="list-group-item"><i class="fa fa-check"></i> Compound - <span class="aaaa">{{ $p->compound->name }}</span></li>
                                            </ul>
                                            <div class="panel-footer" style="overflow: hidden">
                                                <div class="col-sm-12">
                                                    <button type="button" class="btn btn-info btn-block btn-icon icon-left delete_button"
                                                            data-toggle="modal" data-target="#DelModal"
                                                            data-id="{{ $p->id }}">
                                                        <i class="fa fa-send"></i> Invest Under This Package
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                @endif
                                @endforeach
                            </div>

但我建议您不要使用foreach,因为您已经知道您只需要显示计划ID 3。试试这个:

        <div class="row">

     <?php $p = $plan["your_desired_id"]; ?> // means 2 or 3 .. whatever your desired id

     <div class="col-sm-4 text-center">
      <div class="panel panel-info panel-pricing">
     <div class="panel-heading">
     <h3 style="font-size: 28px;"><b>{{ $p->name }}</b></h3>
                                            </div>
    <div style="font-size: 18px;padding: 18px;" class="panel-body text-center">
     <p><strong>{{ $p->minimum }} {{ $basic->currency }} - {{ $p->maximum }} {{ $basic->currency }}</strong></p>
                                            </div>
 <ul style='font-size: 15px;' class="list-group text-center bold">
    <li class="list-group-item"><i class="fa fa-check"></i> Commission - {{ $p->percent }} <i class="fa fa-percent"></i> </li>
                                                <li class="list-group-item"><i class="fa fa-check"></i> Time - {{ $p->time }} times </li>
                                                <li class="list-group-item"><i class="fa fa-check"></i> Compound - <span class="aaaa">{{ $p->compound->name }}</span></li>
                                            </ul>
                                            <div class="panel-footer" style="overflow: hidden">
                                                <div class="col-sm-12">
                                                    <button type="button" class="btn btn-info btn-block btn-icon icon-left delete_button"
                                                            data-toggle="modal" data-target="#DelModal"
                                                            data-id="{{ $p->id }}">
                                                        <i class="fa fa-send"></i> Invest Under This Package
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                            </div> 

答案 2 :(得分:0)

如果您需要从集合中找出单个计划值。 您可以通过它的计划ID

找到它
$plan = Plan::find(3);

将此内容写入控制器,然后使用with。

将其传递给查看刀片文件

示例:

return view("blade file name")->with(['plan'=>$plan]) 

稍后在您的刀片文件中,只需访问它的字段。

{{$plan->field_name}}