想要隐藏当年的每月定价

问题描述 投票:0回答:1

我正在 Laravel 中创建一个定价计划。它在年和月选项卡中显示 bon 我如何分离数据?

@foreach ($pricing as $price)
    @php
    $options = json_decode($price->options, true);
    @endphp
    @if ($price->frequency_unit == 'month')
        <div class="col-md-6 col-lg-4" data-aos="fade-up-sm" data-aos-delay="50">
            <div class="pricing-card p-6 px-lg-10 py-lg-8 rounded-4 h-full bg-">
                <h3 class="text-primary-dark fw-medium mb-0">{{ $price->name}}</h3>
                <h1 class="display-2 fw-semibold text-white mb-0 mt-4 price monthly">{{ $price->price}}</h1>
                <h1 class="display-2 fw-semibold text-white mb-0 mt-4 price yearly d-none"></h1>
                <p class="text-white lead fw-normal mt-4 mb-0">
                    {{ $price->description}}
                </p>
                <a href="pricing-plan.html"
                    class="pricing-btn btn btn-lg w-full fs-4 lh-sm mt-9 btn-dark-blue-3">Choose Plan</a>
                <ul class="pricing-list d-flex flex-column gap-5 fs-lg mt-9 mb-0">
                    <li>Max Email {{ number_format($options['email_max'] / 1000, 0) }}k</li>
                    <li>Email List @if ($options['list_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['list_max']}}
                        @endif</li>
                    <li>Subscriber
                        @if ($options['subscriber_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['subscriber_max']}}
                        @endif</li>
                    </li>
                    <li>Campaign
                        @if ($options['campaign_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['campaign_max']}}
                        @endif</li>
                    </li>
                    <li>Automation
                        @if ($options['automation_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['automation_max']}}
                        @endif</li>
                    </li>
                </ul>
            </div>
        </div>
    @endif
    @if ($price->frequency_unit == 'year')
        <div class="col-md-6 col-lg-4" data-aos="fade-up-sm" data-aos-delay="50">
            <div class="pricing-card p-6 px-lg-10 py-lg-8 rounded-4 h-full bg-">
                <h3 class="text-primary-dark fw-medium mb-0">{{ $price->name}}</h3>
                <h1 class="display-2 fw-semibold text-white mb-0 mt-4 price yearly">{{ $price->price}}</h1>
                <h1 class="display-2 fw-semibold text-white mb-0 mt-4 price monthly d-none"></h1>
                <p class="text-white lead fw-normal mt-4 mb-0">
                    {{ $price->description}}
                </p>
                <a href="pricing-plan.html"
                    class="pricing-btn btn btn-lg w-full fs-4 lh-sm mt-9 btn-dark-blue-3">Choose Plan</a>
                <ul class="pricing-list d-flex flex-column gap-5 fs-lg mt-9 mb-0">
                    <li>Max Email {{ number_format($options['email_max'] / 1000, 0) }}k</li>
                    <li>Email List @if ($options['list_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['list_max']}}
                        @endif</li>
                    <li>Subscriber
                        @if ($options['subscriber_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['subscriber_max']}}
                        @endif</li>
                    </li>
                    <li>Campaign
                        @if ($options['campaign_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['campaign_max']}}
                        @endif</li>
                    </li>
                    <li>Automation
                        @if ($options['automation_max'] == -1)
                        Unlimited
                        @else
                        {{ $options['automation_max']}}
                        @endif</li>
                    </li>
                </ul>
            </div>
        </div>
    @endif
@endforeach

这是我的控制器

public function index(Request $request)
    {
        $defaultSettings = Setting::defaultSettings();
        $siteName = $defaultSettings['site_name']['value'];
        $currentYear = date('Y');
        $pricing = Plan::where('status', 'active')->get();


        return view('homepage', compact('siteName', 'currentYear', 'pricing'));
    }

我尝试了 yt ppl 告诉的一些事情,但我搞砸了很多想要隐藏每年和每年定价中的每月定价到每月如何解决这个问题我试图在 h1 中写入 if 但它不起作用我不知道如何解决这个问题请解释如何解决这个问题

php laravel laravel-blade laravel-livewire
1个回答
0
投票

不要重写整个 div,因为除了

monthly
yearly
的 CSS 类之外,两者看起来都一样。只需使用 if-else-if 结构即可。

@foreach ($pricing as $price)
    @php
        $options = json_decode($price->options, true);
    @endphp
    <div class="col-md-6 col-lg-4" data-aos="fade-up-sm" data-aos-delay="50">
        <div class="pricing-card p-6 px-lg-10 py-lg-8 rounded-4 h-full bg-">
            <h3 class="text-primary-dark fw-medium mb-0">{{ $price->name}}</h3>
            @if($price->frequency_unit == 'month')
                <h1 class="display-2 fw-semibold text-white mb-0 mt-4 price monthly">{{ $price->price}}</h1>
            @elseif($price->frequency_unit == 'year')
                <h1 class="display-2 fw-semibold text-white mb-0 mt-4 price yearly"></h1>
            @endif
            <p class="text-white lead fw-normal mt-4 mb-0">
                {{ $price->description}}
            </p>
            <a href="pricing-plan.html"
                class="pricing-btn btn btn-lg w-full fs-4 lh-sm mt-9 btn-dark-blue-3">Choose Plan</a>
            <ul class="pricing-list d-flex flex-column gap-5 fs-lg mt-9 mb-0">
                <li>Max Email {{ number_format($options['email_max'] / 1000, 0) }}k</li>
                <li>Email List @if ($options['list_max'] == -1)
                    Unlimited
                    @else
                    {{ $options['list_max']}}
                    @endif</li>
                <li>Subscriber
                    @if ($options['subscriber_max'] == -1)
                    Unlimited
                    @else
                    {{ $options['subscriber_max']}}
                    @endif</li>
                </li>
                <li>Campaign
                    @if ($options['campaign_max'] == -1)
                    Unlimited
                    @else
                    {{ $options['campaign_max']}}
                    @endif</li>
                </li>
                <li>Automation
                    @if ($options['automation_max'] == -1)
                    Unlimited
                    @else
                    {{ $options['automation_max']}}
                    @endif</li>
                </li>
            </ul>
        </div>
    </div>
@endforeach
© www.soinside.com 2019 - 2024. All rights reserved.