How can i insert data in relation table using model

0 votes

i have a two table 1).customers (id,name,address)
and 2nd table Orders(id,item,price,Customers_id)

This is my model

This is my controller

Any help please?

Aug 21, 2020 in Java-Script by Alisha
• 140 points
1,339 views
Hi, @Alisha,

Insert first in customers table and with the insert id, then insert in the orders table.
but i wanted to have data inserted from model how can that be possible?

1 answer to this question.

0 votes

Hello @Alisha,

Try to work using the model and not the DB, there are many features that you loose because of it.
$user->order()->create( $arrayOfdata)

Hope it works!!
Thank you!!

answered Aug 24, 2020 by Niroj
• 82,840 points
Thank you for your help

Can you say me which code i have to write in contoller so my data add in customer and order table?

Hello @Alisha,

The code change depending of the type of relationship, 1-1, n-n, 1-n. so there is no specific code, it will be customized according to user requirement

Yes sir but how can i use will u please solve it i tried lot but cant find solution or any doc you can refer would be great

You can find all the details depending of the type of relationship, 1-1, n-n, 1-n here:https://laravel.com/docs/7.x/eloquent-relationships#inserting-and-updating-related-models

Hope it helps!!

Thank you so much.....

Related Questions In Java-Script

+1 vote
1 answer

How can we send message multiple time to a specific person or group in whatsapp using loop?

Hii @kartik,  This is simple task to send single ...READ MORE

answered Feb 28, 2020 in Java-Script by Niroj
• 82,840 points
18,627 views
0 votes
2 answers

How can I set a session var using javascript and get it via php code?

Yes it is possible. You can either ...READ MORE

answered Aug 9, 2020 in Java-Script by Okugbe
• 280 points
28,778 views
0 votes
1 answer

How do I post a form in laravel 5 using ajax?

Hello @kartik, You can solve this error by ...READ MORE

answered Jun 11, 2020 in Java-Script by Niroj
• 82,840 points
2,827 views
0 votes
1 answer

How can I Abort Ajax requests using jQuery?

Hello @kartik, It is always best practice to ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,840 points
2,902 views
0 votes
1 answer
0 votes
1 answer

How can I start learning Node.js and its related components?

Node.js is an open source server environment ...READ MORE

answered Jun 6, 2019 in Career Counselling by ArchanaNagur
• 2,360 points
692 views
0 votes
1 answer

How do I start studying Node.JS to create a restful API?

Node.js is an open source server environment ...READ MORE

answered Jun 11, 2019 in Others by ArchanaNagur
• 2,360 points
984 views
0 votes
1 answer

How to access url for the current if statement of laravel?

Hello @ subham , If you want to access the ...READ MORE

answered Aug 7, 2020 in Laravel by Niroj
• 82,840 points
1,374 views
0 votes
2 answers

How can I set focus on an element in an HTML form using JavaScript?

Hi Kartik, try the following script <script>  (window.onload = ...READ MORE

answered Sep 24, 2020 in Java-Script by Okugbe
• 280 points
1,848 views
0 votes
1 answer

How can I insert a line break into a <Text> component in React Native?

Hello @kartik, This should do it: <Text> Hi~{"\n"} this is a ...READ MORE

answered Sep 21, 2020 in Java-Script by Niroj
• 82,840 points
15,812 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP