简体   繁体   English

如何同时导入多个表数据?

[英]How to import multiple table data at the same time?

I have 3 tables我有 3 张桌子

  1. user table用户表
  2. story table故事桌
  3. poem table诗桌

and also have并且还有

  1. user controller用户 controller
  2. story controller故事 controller
  3. poem controller诗 controller
  4. dashboard controller仪表板 controller

Every table has one common data field, which is the user phone-number .每个表都有一个公共数据字段,即用户phone-number

So I want to show all post in user dashboard when user login,所以我想在用户登录时在用户仪表板中显示所有帖子, 在此处输入图像描述 I need help to proceed with this what is the best and easy way to do that?我需要帮助才能继续进行此操作,最好和最简单的方法是什么? and how, need help, I'm new to web design以及如何,需要帮助,我是 web 设计的新手

I think, initially you can create Laravel models for each DB tables.我认为,最初您可以为每个数据库表创建 Laravel 模型。 Then create model relationships to each table using hasMany() and belongsTo() functions.然后使用 hasMany() 和 belongsTo() 函数为每个表创建 model 关系。 As you mentioned if mobile number is the foreign key, you can add that table column id as the key to link each models in those model relationship functions.正如您提到的,如果手机号码是外键,您可以添加该表列 id 作为键来链接这些 model 关系函数中的每个模型。 But, I would suggest you may need to create separate two tables for story and poem user related tables to store the user related ids (user_id, poem_id table & user_id, story_id table) since both poem & story can have 1 to many relationships.但是,我建议您可能需要为故事和诗歌用户相关表创建单独的两个表来存储用户相关 id(user_id、poem_id 表和 user_id、story_id 表),因为诗歌和故事都可以有一对多的关系。

Then you can use User::with() function to filter each user related poems & stories In dashboard controller.然后您可以使用 User::with() function 在仪表板 controller 中过滤每个用户相关的诗歌和故事。

On front end vue js, you can send Ajax post request using axios library and load all the data in json format and store in an array.在前端 vue js 上,您可以使用 axios 库发送 Ajax 发布请求,并以 json 格式加载所有数据并存储在数组中。 On the relevant template location you can use v-for to loop the array and show the stored array data.在相关模板位置,您可以使用 v-for 循环数组并显示存储的数组数据。

Hope this will help you to sort it out.希望这可以帮助您解决问题。

Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM