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
173 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 23, 2020 by Niroj
• 82,780 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,780 points
2,586 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
9,143 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,780 points
510 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 17, 2020 in Java-Script by Niroj
• 82,780 points
1,005 views
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,340 points
174 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 10, 2019 in Others by ArchanaNagur
• 2,340 points
209 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,780 points
245 views
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
139 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
146 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 20, 2020 in Java-Script by Niroj
• 82,780 points
4,843 views