简体   繁体   中英

How to import multiple table data at the same time?

I have 3 tables

  1. user table
  2. story table
  3. poem table

and also have

  1. user controller
  2. story controller
  3. poem controller
  4. dashboard controller

Every table has one common data field, which is the user 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

I think, initially you can create Laravel models for each DB tables. Then create model relationships to each table using hasMany() and belongsTo() functions. 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. 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.

Then you can use User::with() function to filter each user related poems & stories In dashboard 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. On the relevant template location you can use v-for to loop the array and show the stored array data.

Hope this will help you to sort it out.

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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