Laravel 从 Mysql 数据库创建到控制器的动态路由
问题描述
我有下表:mysql 数据库中的 group_pages 页面名称路由名称:
I have the following table: group_pages in mysql database with page name route name :
我要做的是在我的 : routes.php 中创建动态路由?
what I am trying to do is to create dynamic routes in my : routes.php ?
如果我去哪里,例如: /about
它将去 AboutController.php
(这将是动态创建的)这可能吗?是否可以创建动态控制器文件?
Where if I go to for example: /about
it will go to AboutController.php
( which will be created dynamically) is that possible? is it possible to create a dynamic controller file?
我正在尝试创建链接到控制器的动态页面路由
I am trying to create dynamic pages routes that links to a controller
示例我想在我的 routes.php
推荐答案
这不是创建动态页面的正确方法,您应该使用数据库并将所有页面保留在数据库中.例如:
This is not the right way to create dynamic pages instead, you should use a database and keep all pages in the database. For example:
然后创建Page
Eloquent
模型:
然后为CRUD
创建Controller
,你可以使用resource
控制器或普通控制器,例如通常是PageController
:
Then create Controller
for CRUD
, you may use a resource
controller or a normal controller, for example, normally a PageController
:
views/page/index.blade.php
视图文件:
要显示页面,请创建这样的路由:
To show pages create a route like this:
要访问一个页面,您可能需要像这样的 url/link
:
To access a page, you may require url/link
like this:
这是一个粗略的想法,尝试实现这样的东西.
This is a rough idea, try to implement something like this.
这篇关于Laravel 从 Mysql 数据库创建到控制器的动态路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!