如何在使用播种机的laravel中使用mysql或json中的html代码(how to have html codes in mysql or json in laravel using seede

编程入门 行业动态 更新时间:2024-10-26 18:23:15
如何在使用播种机的laravel中使用mysql或json中的html代码(how to have html codes in mysql or json in laravel using seeder)

我正在尝试构建一个网站构建器,我想手动存储插件/ portlet的HTML结构,用户可以拥有结构和他们插入的任何可编辑数据,使用控制器中的序列化存储到数据库中,现在我知道MySQL不保存html数据或者说它存储不安全,我决定将基本结构存储为JSON格式到一个单独的文件中,现在我不希望将这些JSON文件存放在我的公共文件夹目的地,我浏览了Seeder文档和教程,找到了文件的路径并获取了JSON数据。 还经历了本教程

并且遇到了以下课程:

<?php use Illuminate\Database\Seeder; use App\User; class PortletTableSeeder extends Seeder { public function run() { $json = File::get("database/data/portlets.json"); $data = json_decode($json); foreach ($data as $obj) { 'id' => $obj->id, 'html_code' => $obj->html_code, 'dummy_data' => $obj->dummy_data, //more objects.. )); } } } ?>

这是执行此操作的正确方法吗? 并将其调用到刀片文件中,例如,如果gulpfile中的主题/ portlet的ID可以是这样的话,我就有名称的mixstyles:

<link href="css/{{$id}}.css" rel="stylesheet" type="text/css" />

I'm trying to build a website builder, where I want to store HTML structure of the plugins/portlets manually, where user can have the structure and whatever editable data they are inserting, gets stored into database using serialize in the controller, now I came to know MySQL doesn't hold html data or say it is unsafe to store, I decided to store the basic structure into JSON format into a separate file, Now I don't want to have these JSON files in my public folder destination, I went through the Seeder documentation and tutorial to find path of the file and get the JSON data. Also went through this tutorial

and came across following class:

<?php use Illuminate\Database\Seeder; use App\User; class PortletTableSeeder extends Seeder { public function run() { $json = File::get("database/data/portlets.json"); $data = json_decode($json); foreach ($data as $obj) { 'id' => $obj->id, 'html_code' => $obj->html_code, 'dummy_data' => $obj->dummy_data, //more objects.. )); } } } ?>

Is it the correct way of executing this? and calling it into blade file for example I have mixstyles by the name if id of the theme/portlet in gulpfile can I have like this:

<link href="css/{{$id}}.css" rel="stylesheet" type="text/css" />

最满意答案

我认为最好的方法是在前端管理HTML代码(使用刀片)。 从DB获取数据集并在前端创建动态页面。

您可以设计单独的刀片文件并动态加载。

public function create() { $data = Portlet::get(); if(condition) return view('design.form1',compact('data')); else return view('design.form2',compact('data')); }

如果你想在mysql DB中保存json数据,请点击链接。

如何在MySQL数据库中使用JSON数据字段

I think best way to do this is manage HTML code in front end (using blade). Get data set from DB & create dynamic pages in front end.

You can design separate blade files & load in dynamically.

public function create() { $data = Portlet::get(); if(condition) return view('design.form1',compact('data')); else return view('design.form2',compact('data')); }

If you want to keep json data in mysql DB please follow the link.

How to Use JSON Data Fields in MySQL Databases

更多推荐

本文发布于:2023-08-05 06:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428772.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:播种机   代码   如何在   laravel   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!