使用Laravel段方法动态放置活动类(不工作)

时间:2017-04-23 16:01:20

标签: laravel segment

我有四个步骤。每个步骤的网址都是 -

基本信息localhost/project/public/user/sell/basic-info
产品信息localhost/project/public/user/sell/5/product-info
照片localhost/project/public/user/sell/5/photos
价格信息localhost/project/public/user/sell/5/price-info

我想,当我在basic-info时,基本信息步骤必须有active类,其余步骤将有disabled类。

当我处于product-info时,基本信息步骤将没有任何类,产品信息步骤将有active类,其后的其余步骤将disabled上课等等。

下面是图片。

enter image description here

这是我的代码 -

<div class="ui mini top four attached steps">
    <div class="{{ Request::segment(3) === 'basic-info' ? 'active' : '' }} step">
        <i class="info circle icon"></i>
        <div class="content">
            <div class="title">Basic Info</div>
            <div class="description">Enter the basic information.</div>
        </div>
    </div>
    <div class="{{ Request::segment(4) === 'product-info' ? 'active' : Request::segment(3) === 'basic-info' ? 'disabled' : '' }} step">
        <i class="help circle icon"></i>
        <div class="content">
            <div class="title">Product Info</div>
            <div class="description">Enter your product details.</div>
        </div>
    </div>
    <div class="{{ Request::segment(4) === 'photos' ? 'active' : Request::segment(3) === 'basic-info' ? 'disabled' : Request::segment(4) === 'basic-info' ? 'disabled' : '' }} step">
        <i class="image icon"></i>
        <div class="content">
            <div class="title">Photos</div>
            <div class="description">Upload the photos of product.</div>
        </div>
    </div>
    <div class="{{ Request::segment(4) === 'price-info' ? 'active' : Request::segment(3) === 'basic-info' ? 'disabled' : Request::segment(4) === 'basic-info' ? 'disabled' : Request::segment(4) === 'basic-info' ? 'disabled' : '' }} step">
        <i class="rupee icon"></i>
        <div class="content">
            <div class="title">Price</div>
            <div class="description">Enter the price</div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

我建议为此事创建一个帮助函数。

以下是我在一个应用中使用的内容:

<?php

namespace App\Helpers;
use Route;

class Helper
{

    /*
    |--------------------------------------------------------------------------
    | Detect Active Route
    |--------------------------------------------------------------------------
    |
    | Compare given route with current route and return output if they match.
    | Very useful for navigation, marking if the link is active.
    |
    */
    public static function isActiveRoute($route, $output = "active")
    {
        if (Route::currentRouteName() == $route) return $output;
    }
}

config\app.php注册课程和Helper

等别名

'Helper' => App\Helpers\Helper::class, //my custom functions

然后您可以像以下一样使用它:

class="{{ Helper::isActiveRoute('route.name') }}"