如何在 Laravel 5.1 中创建动态菜单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31758627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:05:52  来源:igfitidea点击:

How to create Dynamic menus in laravel 5.1?

phplaravellaravel-5laravel-5.1

提问by scott

I am developing an website there I need to create dynamic menus like wordpress .but i am new to laravel .before asking question here, followed below tutorial but didn't got how to do?

我正在那里开发一个网站,我需要创建像 wordpress 这样的动态菜单。但我是 laravel 的新手。在这里提出问题之前,按照下面的教程进行操作,但不知道该怎么做?

Refereed:

裁判:

http://learninglaravel.net/laravel-dynamic-menu-tutorial/link

http://learninglaravel.net/laravel-dynamic-menu-tutorial/link

http://laravel.io/forum/04-16-2014-dynamic-menu-system

http://laravel.io/forum/04-16-2014-dynamic-menu-system

https://laracasts.com/discuss/channels/general-discussion/dynamic-menu

https://laracasts.com/discuss/channels/general-discussion/dynamic-menu

回答by poashoas

Better late then never, but I've just started learning Laravel too. Start with the following basic tutorials. It might be usefull for you or someone else who reads this question.

迟到总比没有好,但我也刚开始学习 Laravel。从以下基本教程开始。它可能对您或阅读此问题的其他人有用。

Skip the first stepif you just want to integrate your first link into a package right away.

如果您只想立即将第一个链接集成到包中,请跳过第一步

1:

1:

First I've just dumped the following in my project folder just to make it work. NOTE! Read the comments below because there is a typo in the tables "role" and "roles" somewhere. Second of all: if you already have a "users" table by using the "migration" and "seed" files that are present in laravel, Add a "role_id" field to the "users" table. The tutorial works with the build-in authorization / login from Lavarel. You might want to figure that out first.

首先,我只是将以下内容转储到我的项目文件夹中以使其正常工作。笔记!阅读下面的评论,因为表“role”和“roles”的某处有错别字。其次:如果您已经通过使用 laravel 中存在的“迁移”和“种子”文件拥有一个“用户”表,请在“用户”表中添加一个“role_id”字段。本教程使用 Lavarel 的内置授权/登录。你可能想先弄清楚这一点。

https://gist.github.com/drawmyattention/8cb599ee5dc0af5f4246

https://gist.github.com/drawmyattention/8cb599ee5dc0af5f4246

2:

2:

Later on I've followed the following instructions just to make a basic setup for a package:

后来我按照以下说明对包进行了基本设置:

https://laracasts.com/discuss/channels/tips/developing-your-packages-in-laravel-5

https://laracasts.com/discuss/channels/tips/developing-your-packages-in-laravel-5

3:

3:

If you need any css, javascript or view files copied from your package to your project folder read the following:

如果您需要将任何 css、javascript 或视图文件从您的包复制到您的项目文件夹,请阅读以下内容:

http://laravel.com/docs/5.0/packages

http://laravel.com/docs/5.0/packages

4:

4:

Then at last, try to figure out what your Menu thingie is actualy doing. Take your first link to get some inspitation about how to do stuff.

然后最后,试着弄清楚你的菜单上的东西实际上在做什么。使用您的第一个链接来获得有关如何做事的灵感。

Do you want to retrieve a list of all controllers and actions that might be menu-items? It's possible but you might have to google it.

您想检索可能是菜单项的所有控制器和操作的列表吗?这是可能的,但你可能需要谷歌一下。

And when you add one of those generated list items to a menu: create an action with ajax to add a menu-item to the database. Get those items from the database in a view-template and create the menu, I guess they use a "facade" class for it but correct me if I am wrong. A facade class can be called like Menu::create_menu_items();I am going to try the same thing and realy do it step by step.

当您将这些生成的列表项之一添加到菜单时:使用 ajax 创建一个操作以将菜单项添加到数据库中。从视图模板中的数据库中获取这些项目并创建菜单,我猜他们使用了“facade”类,但如果我错了,请纠正我。可以调用外观类,就像Menu::create_menu_items();我要尝试相同的事情并真正一步一步地做一样。