Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:13:31+00:00 2026-06-14T15:13:31+00:00

I want to build a menu from an array in Laravel. What I’m currently

  • 0

I want to build a menu from an array in Laravel. What I’m currently doing is putting the array in a view

$menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];

and then looping through it to generate the menu:

<section>
    <!-- Left Nav Section -->
    <ul class="left">
        <li class="divider"></li>
        @foreach($menu as $key => $nav)
            <li class="has-dropdown">
                <a href="#" class="active">{{ $key }}</a>
                <ul class="dropdown">
                    @foreach($nav as $subnav)
                        <li>
                            <a href="">{{ $subnav }}</a>
                        </li>
                    @endforeach
                </ul>
            </li>
        @endforeach
    </ul>
</section>

Is there any other way that I can achieve the same result without putting the data in the view?

I also tried creating a constructor function in the controller:

public function __construct() {
    $menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];

    return $menu;
}

But I guess that is not how it works. I appreciate any ideas on how I can go about this. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:13:32+00:00Added an answer on June 14, 2026 at 3:13 pm

    If you’re using controller layouts you can bind data to the layout from within the constructor. Just make sure you call the parent constructor first so that the layout is instantiated properly.

    public function __construct()
    {
        parent::__construct();
    
        $this->layout->menu = ['home', 'users' => ['create users' , 'update user', 'activity log']];
    }
    

    That will bind a $menu variable to the layout, and will also be available to any nested views that are used with Blades @include.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build my own menu from the beginning so to be able
i want to show a menu in some pages. the menu is build from
I want to build a Web page (in Asp.Net) containing a Dynamic Menu where
I want to build a python program that deletes all the photos from my
i have this situation: i have to build a menu with datasource from the
I have an array, named Images and want to get on value from it.
I'm trying to create a plugin like script for adding to a menu array....
I'm trying to build a vertical, static ASP Menu from the SiteMap file in
I need to discover the origin of a page view: click from Menu, Banner,
I have a menu built with <ul> and <li> tags. I want to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.