Laravel-Backpack/MenuCRUD

Help to create a sidebar menu in my homepage

Sikyn opened this issue · 5 comments

Sikyn commented

Hello guy,

I apologize in advance for my pathetic English skill.

I used your Laravel-Backpack for create a menu in the top of my home page and a footer, he regroup different categories of products in a commercial site.

When i add a item in the database, the values "page_id" ; "lft" , "rgt", and "depth" are initialized at NULL :(

In which file they are initialized ?
Have you got a hypothèse to fix it ?

Thank you in advance if I have an answer, if not, never mind.

Hi @Sikyn ,

Having them NULL in the database should be OK. They're automatically changed when the admin reorders/nests the items. And until then, why add a value, if they're top-level?

But if you'd like, you can set a default value (0, most likely) in your database. You can do that using a migration, something like:

Schema:: table('menu_items', function ($table) {
            $table->integer('lft')->unsigned()->default(0)->change();
            $table->integer('rgt')->unsigned()->default(0)->change();
            $table->integer('depth')->unsigned()->default(0)->change();
        });

Or if you're not using auto-deployment, you can do it directly in command line or phpMyAdmin, or something like that.

Cheers!

Sikyn commented

Thank's you for you answer !

You have right, when I reoders the items, the differents value (lft/right/depth) are initialized/calculated... it's my bad because I have tried with a new database and I did not think to use the functionality "reorder".

But now, my problem is that each time i sort a carategorie or a subcategories of my menu using "reorder", a ramdon item lost his "parent_id". He takes as value : NULL. (So it can not be displayed correctly)
To my point of wiew, it's maybe because i have a lot of item and you have possibly set a limit on the number of item ?
I always have 90% of "page_id" equal at NULL but I don't know the utility of this variable.

It's been for days that I look for a solution and if you're French I can give you more details in that language, it could be useful.

Thank you for your time :)

Hi @Sikyn ,

  • parent_id should be null if the item does not have a parent (that means: it's not nested, so it's a level zero menu item, it's not a subitem);
  • page_id is NULL when you add a menu item that is not connected to a different page (ex: a link to an external page);

Unfortunately, my French is very very rusty. Haven't read/spoken/heard it in the past 9 years. I'd probably understand, but I'm 90% sure it will end up in Google Translate :-)

A bientot! ;-)

@tabacitu Hello there.

I don't want to open a new issue just for a little stupid question.

❓ Are there any examples of using MenuCRUD? What should I do after I added some items to menu? Should I add somewhere a special code or what?

Wait, I've got an idea! 💡 maybe it's just a helper to create a menu for my application in DB and then I have to show it on my pages by myself? If so than no need to examples, I'll manage it by myself.
And the same story with the NewsCRUD?

Thanks 🍺

Hi @andreich1980 ,

Your intuition was correct - Backpack\MenuCRUD and Backpack\NewsCRUD just handle the management and stores them in the database. For the front-end there is no "right way" to do it, you should find a way that fits your project.

For a front-end example for MenuCRUD, follow this thread: #3

Cheers!