0

I have four steps. Urls of each steps are -

basic-info : localhost/project/public/user/sell/basic-info
product-info : localhost/project/public/user/sell/5/product-info
photos : localhost/project/public/user/sell/5/photos
price-info : localhost/project/public/user/sell/5/price-info

I want, when I am at basic-info then the basic-info step must have active class and rest of the steps will have disabled class.

And when I am at product-info then, the basic-info step will not have any class and product-info step will have active class and rest of the steps after that will have disabled class, and so on.

Below is the image.

enter image description here

Here is my code -

<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>
linktoahref
  • 7,812
  • 3
  • 29
  • 51
Keshari Nandan
  • 1,040
  • 9
  • 22

1 Answers1

0

I recommend creating a Helper function for this matter.

Here is what I'm using in one app:

<?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;
    }
}

Register the class in config\app.php and an alias like Helper

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

and you can then use it like:

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

Angelin Calu
  • 1,905
  • 8
  • 24
  • 44