How to Move Cart data to Order Table in Laravel | Laravel E-Ccommerce Project Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Yamin and welcome to L project tutor for beginner in this tutorial we're going to move the card data to the order table so in the order table we have name receiver address phone number phon ID and the user ID and we also have one more problem called status whether the product is delivered or not deliver or in progress so first of all let's go create the order table so for it let will just go to the project directory and let me just open on BR here we say CMD then press enter and here I'm going to create a order table so for we need to say here P partition make clone we'll create a model and mation at the same time our table them will be ordered and we give over here minus L it means migration so we press enter and then it has a model and migration is created so let's go back to our code and if we just go to models app then models here you can see we have order. model over here and right now if we just go to our uh database then mation and inside migration we have this order T so here let's go and add s column so let's say here donor table this Arrow sign we are going to say our screen then we say it will be name let's just make it null L and let me just copy this and I paste it this five times 1 2 3 4 and five so after name we'll have over here deceiver address so let's say what here rcore address here we say phone number let's just say phone after fold we have their status let's say here status and Status will have a default value so here we are going to say default and that default Val will be there say progress or let's say in progress this will be the default Val for status and we have two more column that will be product ID and user ID and we use those as a foreign key so since this is a foreign key uh so we are going to S here un signed integer and here we're going to say user ID user uncore ID so we'll get the user ID from the user table and after that okay let me just copy this and I'm going to paste it here and this will be product ID so let's say here product ID and since this is a foreign key so it won be nullable and let's make it un sign pink integer let's say Here Pink integer and after that you know to make it foreign key we need to write one more line that is dollar table Arrow sign for then we to file bracket to cation user _ ID which is basically this one and the reference we need to make sure the reference so we need to say what here reference and it will be it will be ID and references and this ID will come from the user table so ID on we say there users then we set there on delete it will be cask so right now let me just copy this and we do the sale for the product so here we're going to sa product ID product ID and here L of users we are going to L the product table so we say have products and it will be on update and okay I made a spending mistake it will be user user ID so let's set this and let's go back to our Command prom and we're going to sell on here PHP r t migrate and press enter and there you can see on order T is migrated so right now you can just go back to our browser then database let me just refresh here and here you can see we have a order table if I click on order table here name receiver address pH number Status user ID and P ID so let's go get some input field over here call name address and phone number receiver name receiver address and phone number and the confirm order button and we'll get some product ID and user ID from the T so let's go back to the code and we'll go to our my card. bl. PHP and here you can see our C started over here so before this let me just mention a de here then in this T we're going to have a f so we say here form then in this form let's mention another team here we going to say level level will be let's say reer receiver L and for it we're going to give a input F so input type will be text and here we're going to send name it will be name let me just open this and I'm going to paste it on two and three time so after receiver name let's say here receiver address and here let's say receiver form so for address let's use text area we are going to S here text area and for this text area we need a name this name will be address and B phone type will be text okay that's find and name equal to it will be phone and this one will be the confirm butle so in input type it will be submit and here we are going to set value it will be place order and for this input type submit let's mention it Bo typ class let's say the class name will be BTN BN primary save let's go back refresh and there you can see so obviously we are going to make some design for this so let's go back to the code again and first of all for this team let's just mention a class and let's say class name will be order underscore te CH so let's put the top in the style where will to say dot _ d we get to second bracket let's here ping right it will be 150px and marging top it will be let's say minus 200x if you know save it there will be some padding over here and our phone will be Ed at the Top If we now refresh there you can see so right now let's go and add some design over here so for it let's go back and here for the level we're going to write some CSS so level we say want here display it will be be in Line blog and we set with it will be 150 BX and this was for the level so let's write some CSS for DDF so let's just mention a class let's over here Dore let's say Gap let me just copy this and I'm going to paste it for each D this is the last one so let's go and write some CSS properties so here in the style where we say dot de underscore Gap then to Second bracket we are going to set padding it will be let's say 20 save it then refresh here and there you go I think padding is too much let's just uh make the padding 100 PX over here for order PG refresh uh okay I think this is fine so right now what we do is that here in the deer name address and phone number we're going to get the login user okay let me just go to the user table we want to get the logged in user name phone number and address and if the user don't take and modify it so let's go back to the code and do this code down and here in order to get logged in username in the input Feld we just need to say what here hello and then we need to say here on double prone user to Fage there this Arrow sign we need to S our name so for where it will C if you go to the user table uh in the insert hercy name so this name will come about here and with need to give to Second bracket as well so it will get the loged in username over here so if you know say then refresh here there you can see you a to get the login user name so the same way we a to get the user address and phone number so let me just copy this value from here control C and for text area we paste it here and we're going to set here address and for form we going to say here this will be form and for text area there is no need to mention the value here let me just remove it save it then you press and there you can see so the user will will modify the address let's say from here Road 7 or state 5 house eight whatever so let's just keep it as the way this and right now mod is that the in click on this PR order button those data the product ID and user ID will be stored in the order da care so for in the form let's mention over here action then we s here method method will be post then we send here a of csrf token so in the action let me just give to Second bracket let's mention URL to F bracket s let's say here confirm uncore order let's send this and let's go to our rout then web. PHP and let me just try to go down then it will just copy this route we paste it here the route will be post we say here post and the route name the route name us phomore order so we are going to set here onore order we use the home controller function name will be F frommore order so let's go to our home controller cre this F we'll go to our app HTTP controller and home controller let me the TR here go down then we're going to send here public F confirm order then to Second bracket then and we need to request some data so we say on here request dollar request so first of all here we are going to declare a variable a dollar order equal to we need to mention the order order but before that we also need to add the order model at the top so let me just copy paste and here we say app back SL model B SL order let me just SC down and here we're going to say order call to New Order which is on war and but before that first of all what we going to do is we're going to get uh those data receiver name address and phone number in a variable so here let me just declare a variable let's say have dollar name equal to we're going to set dollar request this Arrow sign and the name will come from here my. bl. PHP and here it get name equal to name and here it can name to address and name go to P so here we're going to say request name then let me just copy this and I'm going to paste it over here so here we're going to say address let me say what here address and this one will be phone number so we're going to say here phone and after that here you can see that over here in the card we we have multiple product not a single product okay so first of all what we going to do is we are going to go to the uh card table and over here we're going to get the product where the ID user ID is s so here you can see user IDs on one here one two three times so we'll only get the product ID for which the user ID s and that user must be logged in so right now what we are going to do is let me just declare a variable let's say dollar user ID equal to we say here or double BL user then to F Dr this Arrow side ID so this way we will look at the login user ID and we'll store it in this variable and after this we are going to S over here let's say let's say Toller car equal to we are going to mention the that model name let's say here card double clone we say a fire to F bracket to single quotation and then here in the card table we have user underscore ID so we're going to say that user underscore ID command we'll get the loged in user ID so here after this we set here get to F gate like this so what will happen is that we will get that data where the loog in user ID sell in the C so after this we're going to mention it for each group so here let me say for each to five bracket let's say dollar car as let's say dollar cards just make sure that those two variable are different then we get to second bracket and here you can see order equal to New Order so we'll keep it over here inside this for to since we have multiple data so we need to store multiple data in the order table so after this let me just go to the order table uh in the order table we have name is address and phone number so first of all here we're going to say dollar order we'll get the or after the name so we say here name equal to here we already get the name of here from the input field right so we to mention this dollar name here dollar name and after this let me just copy this and paste it here and here so this time we are to mention the reer name here you can see rcore address so here I'm going to say rcore address address and here our variable is this on address so we say here dollar address and this one will be the full so this will come from the database table and this dollar pH phone will come from here so after this we can easily get the logged in user ID by using this user underscore ID so here we are going to say dollar order this Arrow sign we say here user uncore ID equal to we are going to say here this dollar user ID and this user _ ID or user ID we come from here here you can see user _ ID and this col user user ID is this one so after this what we going to do is or we dollar order then this Arrow sign this time you want to get the pant ID and it is a little bit different but first of all let's write over here product _ ID equal to this is SLE this is D from table which is this one _ ID from theorder table and after that here you can see we mention a for of dollar card as dollar cards so we are going to mention this dollar cards here and you can see that in the dollar card we have the all the data for a specific user ID and if we go to the uh card table there you can see for user ID on we have product 8 product ID 8 12 and 11 so since this is a Forest Loop so we'll be a to get all the product data so here we're going to give this Arrow sign and from the card table we have you can see productor ID in the card table so we are going to mention that product uncore ID here like this and after that we just leave to say dollar order is Arrow sign set after saving the we'll keep the user on the same page so we say here return redirect kuas bracket this L sign pad and I also made a spending mare order uh so let me just set this and I hope everything will be okay we want to get the name address phone number user ID and pH ID from the c table and store in the order table let's save it let me just refresh here and if we now click on this place order buttons or let me just change the name work here from user two let's say Adam from Canada 2 let's say Canada Street 7 and phone number is fine okay so we'll now click on place order there can our P reloaded and if we now go to our uh order table okay there is only on data let me check it okay here you can see after storing data we are just directly returning the user back to the same Bas but the Forest Loop is still running so it will only upload the first status so let me just keep this R reing back after the for ISO okay just keep it outside the for Loop second bracket so this should up right now let me just save then let me just delete this data single data from here so let me refresh and here the stop user let's say here Adam and we're going to set here Australia then Okay click on place order right now let me just refresh my table and there you can see our name is Adam uh we have address phone number and if everything is f right now so we are a to upload three card P data to the order table so right now there's one more issue and that is here you can see after uploading the data to the order table we are still showing the foru data in the card table as well so we should remove the data or Del from the card table when we upload the data to the order table so let's go back to the port and after this for is2 what we going to do is yes we're going to sell one here n b card underscore remove equal to we are going to measure our card model name we say our card T Pro we're going to mention the wi condition wi to first bracket to S condition we're going to mention the user _ ID then give a comma just like before we're going to just uh do this user ID which we will get from here and get so we s here dollar user ID then this Arrow sign G and after this we're going to mention for each low we say here for is dollar card uncore remove as let just dollar remove then to Second bracket and here we're going to set so in this card remove variable uh we might have multiple product from the card right so that's why we need to use Forest Loop then here we're going to declare a variable let's say dollar let's say dollar data equal to again we'll mention that that model name double PR fil to first bracket then we are going to mention this remove over here and we will get the ID so here what we are doing is that let we just explain if we just go to the card table and whenever we are confirming the order what we do is that for the same user type user type on on and on WE gener data so here we are just getting the specific data for the card table and then we are getting the ID and the ID is this one ID we get the specific ID and then we delete that so we secure dollar data this Arrow sign delete so if we now say Okay C A RT card so if you know save then you press here let me just D the data from the order table first and uh delete it Okay order table is empty and in the card tab we have five data right so let me just refresh here and click on place order and there you go all the product in the guard is remove so that total card value is zero and we need to fix our design obviously right now and if we go to our database then if we now refresh our card table there is only two data but if you go to the order table there is three data let me just fix the design here so let me just go to my guard and here I think I write about here in the order design we write margin top and 100 uh let's make it 100 sa then refresh okay let's make it 15 P refresh again okay this is fine and right now let's just log out from here and let's log in as a different user let's say here Y in let's keep the password Here click login let's go to our card everything is fine and if you now click on place order there you can see order plac successfully but we should also show the message so let's go to our pH and here we're going to mention that toaster notification so let me just copy this from here contrl C we go down and here and before this back we're going to add the toter message one here we are going to sa P order successfully ordered successfully let save this let me just go to the home and let's add some B let's add this on and this one let's go go card click on P order there c order product successfully mes so this is all for this tutorial I showed you how you can move the DAT from cart table to order table I hope this Tut was useful to you if you have any question or any suggestion just let me know in the comment section make sure to subscribe and I hope to see in the feature to yourbody else
Info
Channel: Web Tech Knowledge
Views: 873
Rating: undefined out of 5
Keywords: laravel tutorial, laravel project, laravel e-commerce project, laravel ecommerce project, laravel project tutorial, laravel ecommerce tutorial, laravel tutorial for beginners, laravel, laravel ecommerce, laravel 11 ecommerce project, ecommerce project in laravel 11, laravel 11 project, laravel 11 ecommerce tutorial, laravel 11 tutorial, laravel ecommerce website tutorial, order product in laravel, how to move data from cart table to order table table in laravel
Id: ojbVxRFbnpI
Channel Id: undefined
Length: 25min 54sec (1554 seconds)
Published: Fri May 10 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.