skip to Main Content

I have a menu made from

'profile' => ['heading' => 'Update your bio, cover and avatar', 'icon' => 'person', 'test' =>'test2'],
        'account' => ['heading' => 'Manage your account settings', 'icon' => 'settings'],
        'wallet' => ['heading' => 'Your payments & wallet', 'icon' => 'wallet'],
        'payments' => ['heading' => 'Your payments & wallet', 'icon' => 'card'],
        'rates' => ['heading' => 'Prices & Bundles', 'icon' => 'layers'],

Then, in blade:

 <div class="d-flex align-items-center">
                        @include('elements.icon',['icon'=>$setting['icon'].'-outline','centered'=>'false','classes'=>'mr-3','variant'=>'medium'])
                        <span>{{ucfirst(__($route))}}</span>
                    </div>

So, how, can I , on blade, add a test to menu with name "Wallet"

I tried make some @IF but doesn’t work

2

Answers


  1. First, you need to define the ‘test’ for ‘wallet’ in the menu array:

    $menu = [
        'profile' => ['heading' => 'Update your bio, cover and avatar', 'icon' => 'person', 'test' =>'test2'],
        'account' => ['heading' => 'Manage your account settings', 'icon' => 'settings'],
        'wallet' => ['heading' => 'Your payments & wallet', 'icon' => 'wallet', 'test' => 'testValue'],
        'payments' => ['heading' => 'Your payments & wallet', 'icon' => 'card'],
        'rates' => ['heading' => 'Prices & Bundles', 'icon' => 'layers'],
    ];
    

    In this example, I added a ‘test’ key to the ‘wallet’ array with a value of ‘testValue’.

    Then, in your Blade template, you can access this value like this:

    <div class="d-flex align-items-center">
        @include('elements.icon',['icon'=>$setting['icon'].'-outline','centered'=>'false','classes'=>'mr-3','variant'=>'medium'])
        <span>{{ucfirst(__($route))}}</span>
        @if (isset($setting['test']))
            <span>{{$setting['test']}}</span>
        @endif </div>
    

    Here, I’ve used an @if directive to check if the ‘test’ key is set for the current menu item ($setting). If it is, then the value of ‘test’ is displayed. If it’s not, nothing is displayed.

    Login or Signup to reply.
  2. In your blade, when you loop through your menu items, you can check for the array key like this:

    @foreach($menu as $name => $setting)
      @if($name == 'wallet')
        <!-- do something different for wallet -->
      @else
        <!-- do the regular thing here -->
      @endif
    @endforeach
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search