Povilas you are not making silly mistakes. It is much better when you also see other struggling... Nobody know everything and from mistakes we all learn it better.
on 2:18 I was 'oh my god, n+1 detected'! 5:30 when querying by ids, you can use find or findMany (find works the same way as findMany if you pass an array). The second argument is the required columns. So $products = Product::find($card->pluck('product_id'), ['id', 'quantity_left'])->pluck('quantity_left','id') will be same Just in case. P.S. $order->increment() also fires multiple times, could be done outside of foreach() loop.
Maybe my question is stupid, but wouldn't it be better to create a many-to-many relationship between carts and products ? Thank you very much for these daily videos, you are a great inspiration for me ! Best wishes from France 🇨🇵
5:30 Maybe I’m wrong but since there is an Cart::with(‘product’), don’t you have the quantity_left in the result of $cart? Maybe with a different association since you’re working with a jointable. I might overlook something but it feels like you can get away with another query less.
Correct. He doesn't need to query for product again since he already got it. That's why, as he said in the video, refactoring is important. At least got things right first then we can improve another time ;)
Awesome video, always nice to learn some new eloquent/database methods!! The video left me with a question. The checkout just let's the user choose the payment method. So my doubt is: 1) should we remove the itens (quantity) from the database before he actually pays, since there are payments methods that allow you to pay until 3 days for example? 2) Or could we remove the quantity but in some sort of standby? Like adding in the order table some "did he pay" (boolean) collumn and "expiration date" column?
for bigger solutions with storage etc, there are probably something another as solution. for example, as you wrote, stock syncs where putting to cart creates a temporary "on hold" decrementation to avoid ordering and allows users to create a preorders, etc etc. stock counts may be decreased only when products are shipped out. but, as i mentoined, it was a complex stock solution.
Hi Povilas, not about the video, but Laravel Examples. Suggestion: A page where we can see when you add new packages to the site or a notification. It really helped me already, but it is hard to keep track of new things in the website. Something like a Log of new packages added, or even a email notification and maybe, a video about this subject (Audit log). Thank you! Great work as always. Cheers from Brazil.
Thanks Lucas. I thought about it, but I'm not building it as a "news feed" where I would constantly add new examples, I guess I will add some 1000 examples or so and will more-or-less stop adding new things, or add small amount. So not planning to add news notifications at the moment, I'm planning it to be used as "wikipedia" or "google", like on-demand search when you need something.
Thank You, sir you are doing a great job. But I have a silly question (maybe). Assume that we have a busy shop, and multiple users want to buy the same product at the same time. Then what if we have less quantity of that product than the total product orders. And how we can manage the quantity_left and error messages? And in case if a user left with the cart filled and didn't proceed to the payment process.
Well, in a busy shop, the scenario would be even different and more complex, like in ticketing systems people "reserve" the tickets and then they are released to public if not finished purchasing, with some script every 15 minutes, for example.
@@LaravelDaily you are right, I think would have an actual_quantity_left column for final purchase orders and a quantity_left column for temporary up/down. We also can use Jobs and a queue worker for order-jobs.
Thanks. Very interesting. Theoretical question: In a real project I guess You would check stocks before goods are registered in the cart. In this example if we have a busy shop and a lot of items in the cart it could be a problem to check the stocks before the loop (?) maybe a concurent order could get the stock during we process the order (?)
Yes, good catch. I didn't work on all possible exceptions and cases, wanted to just show the main point. If I worked on all scenarios in all my demos, my videos would be 1-hour long and not 5-10 minutes.
question here... on line 70 fetches with eager product, right? then on condition for checking quantity u can skip whole fetching products by ids and instead of use a check for if($cartProduct->product->quantity_left < $cartProduct->qty) ... or im wrong?
We love how every developer could make errors, makes more realistic haha.. Anyway is live wire rendering take resources in server? How about lavarel components? Is it live like live wire? Sorry for my many questions
I've written about it, in a very detailed way, long time ago: laraveldaily.com/how-to-deploy-laravel-projects-to-live-server-the-ultimate-guide/ Also, search for "deploy" on this channel. Realistically, deployment depends on so so so many individual factors, that my way of deployment will not be suitable for 90% of the situations for others.
It's a personal preference, they just like it more. Also, both Tailwind and Vue creators are active in Laravel community, with joint collaborations and specific content for how to use it in Laravel. For example, Bootstrap or React creators don't participate in Laravel community.
Also: you need to wrap the validation in the transaction. What if some other guy orders the items between the validation and your own order? Than the validation was useless and wrong.
I tried that but it's not working and create record whereas i am rollbacking on any sort of exception happen . Can you give little guide on that in your next video would be great 🙂
Not sure if I would add anything mode useful than default Laravel docs in this case. It's also about debugging your own personal code, I can't do the debugging for you, sorry.
Why are we querying the products separately in the first step? Can't we use $cart to get the products as we already have used eager loading to get the related products? $products = $cart->pluck('product.quantity_left', 'product.id')->all();
Hi Sir can you please guide me for, how can I update the cart items for example you have make like everytime you make a cart update items. Some items will be added and some should delete from cart for some increase or decrease the quantity. Will you please guide me how to do so. I can share example for my question also let me know if it's required.
I tell that anyone of age of comprehension CAN become a programmer, but if you cannot grasp the concept of using Google when it is free and available for most (even alt search engines will help you greatly), then you will struggle too much for your own good (but you'll help better devs with getting a job fixing your errors, sort of a 'win - win' situation; call me names, I don't care - that's the truth). I advise you to take your comment, cut off the part of "hoping for your reply" and put it in the search input on Google. First result, done. Do your own f.. research & RTFM!
For race condition, I would introduce the "reservation" of the products and then release the reservations after they finalize the purchase or become available if the transaction isn't complete in, like, 15 minutes.
You can skip querying products, you can use Cart products relationship for everything, can't you? One query to find product, then decrement quantity, all in a loop. Incrementing order total quantity is also in loop? Not good. And you can make $cart->delete(), since you already have it.
Povilas you are not making silly mistakes. It is much better when you also see other struggling... Nobody know everything and from mistakes we all learn it better.
great video! The „mistakes“ make it all the more exciting and instructive. I would like to have your skills
Thank you for the good information. It's very explanatory. It's much better to make mistakes because you're also teaching how to find fault.
This channel is just great! I really appreciate your tutorials, sir!
on 2:18 I was 'oh my god, n+1 detected'!
5:30 when querying by ids, you can use find or findMany (find works the same way as findMany if you pass an array). The second argument is the required columns.
So $products = Product::find($card->pluck('product_id'), ['id', 'quantity_left'])->pluck('quantity_left','id') will be same
Just in case.
P.S. $order->increment() also fires multiple times, could be done outside of foreach() loop.
Maybe my question is stupid, but wouldn't it be better to create a many-to-many relationship between carts and products ? Thank you very much for these daily videos, you are a great inspiration for me ! Best wishes from France 🇨🇵
Maybe it is suitable too, you can try it. The relationships weren't the point of this video, so I didn't emphasize it.
5:30 Maybe I’m wrong but since there is an Cart::with(‘product’), don’t you have the quantity_left in the result of $cart?
Maybe with a different association since you’re working with a jointable.
I might overlook something but it feels like you can get away with another query less.
Correct. He doesn't need to query for product again since he already got it.
That's why, as he said in the video, refactoring is important. At least got things right first then we can improve another time ;)
Awesome video, always nice to learn some new eloquent/database methods!! The video left me with a question. The checkout just let's the user choose the payment method. So my doubt is: 1) should we remove the itens (quantity) from the database before he actually pays, since there are payments methods that allow you to pay until 3 days for example? 2) Or could we remove the quantity but in some sort of standby? Like adding in the order table some "did he pay" (boolean) collumn and "expiration date" column?
There's no one easy way to answer it, I guess I need to shoot a follow-up video with real payment scenario and possible cases like yours.
@@LaravelDaily That would be really nice, some information about how to handle a real payment scenario. Thanks!!
for bigger solutions with storage etc, there are probably something another as solution. for example, as you wrote, stock syncs where putting to cart creates a temporary "on hold" decrementation to avoid ordering and allows users to create a preorders, etc etc. stock counts may be decreased only when products are shipped out. but, as i mentoined, it was a complex stock solution.
Hi Povilas, not about the video, but Laravel Examples. Suggestion: A page where we can see when you add new packages to the site or a notification. It really helped me already, but it is hard to keep track of new things in the website. Something like a Log of new packages added, or even a email notification and maybe, a video about this subject (Audit log). Thank you! Great work as always. Cheers from Brazil.
Thanks Lucas. I thought about it, but I'm not building it as a "news feed" where I would constantly add new examples, I guess I will add some 1000 examples or so and will more-or-less stop adding new things, or add small amount. So not planning to add news notifications at the moment, I'm planning it to be used as "wikipedia" or "google", like on-demand search when you need something.
Thank You, sir you are doing a great job. But I have a silly question (maybe).
Assume that we have a busy shop, and multiple users want to buy the same product at the same time.
Then what if we have less quantity of that product than the total product orders. And how we can manage the quantity_left and error messages?
And in case if a user left with the cart filled and didn't proceed to the payment process.
Well, in a busy shop, the scenario would be even different and more complex, like in ticketing systems people "reserve" the tickets and then they are released to public if not finished purchasing, with some script every 15 minutes, for example.
@@LaravelDaily you are right, I think would have an actual_quantity_left column for final purchase orders and a quantity_left column for temporary up/down.
We also can use Jobs and a queue worker for order-jobs.
@@LaravelDaily did you uploaded any video or course about Laravel Jobs and Queues on the production server?
Thanks. Very interesting. Theoretical question: In a real project I guess You would check stocks before goods are registered in the cart. In this example if we have a busy shop and a lot of items in the cart it could be a problem to check the stocks before the loop (?) maybe a concurent order could get the stock during we process the order (?)
Yes you're probably right, Sorrawut pointed out the same thing in another comment.
Thank you!
Thanks for your video.
But in the video it seems that you can create an empty order without any exception?
Yes, good catch. I didn't work on all possible exceptions and cases, wanted to just show the main point.
If I worked on all scenarios in all my demos, my videos would be 1-hour long and not 5-10 minutes.
question here... on line 70 fetches with eager product, right? then on condition for checking quantity u can skip whole fetching products by ids and instead of use a check for if($cartProduct->product->quantity_left < $cartProduct->qty) ... or im wrong?
We love how every developer could make errors, makes more realistic haha.. Anyway is live wire rendering take resources in server? How about lavarel components? Is it live like live wire?
Sorry for my many questions
Livewire renders content on a server-side, then just replaces HTML with JavaScript
sorry, if u can show proccess in blade checkout, i think this so insightfull video. Please give detail for blade with jquery sir
thanks
Awesome! Thanks
It could be nice if you show us a way to deploy a laravel app in production. Some times ago you asked us how we do it, now it's your turn?
I've written about it, in a very detailed way, long time ago: laraveldaily.com/how-to-deploy-laravel-projects-to-live-server-the-ultimate-guide/
Also, search for "deploy" on this channel.
Realistically, deployment depends on so so so many individual factors, that my way of deployment will not be suitable for 90% of the situations for others.
So we basically need to use try-catch every time?
Awesome tips!
Thank you so much 💐💐
Can y show us an example of installment payment.
hi there, can you please explain solid principle or model functions usage in laravel? please also provide some examples.
awsm
How to display cart items in table using livewire??
This IDE is PHPStorm? If are, whats the theme it is. Thank you.
Yes, Material Darker
I have a question. Why most of the professionals and even the developers of Laravel prefers TailwindCSS and VueJS than the others?
It's a personal preference, they just like it more.
Also, both Tailwind and Vue creators are active in Laravel community, with joint collaborations and specific content for how to use it in Laravel.
For example, Bootstrap or React creators don't participate in Laravel community.
Also: you need to wrap the validation in the transaction. What if some other guy orders the items between the validation and your own order? Than the validation was useless and wrong.
Can we use DB::beginTransaction(); and commit and rollback control in our hand with try catch finally ?
Yes.
I tried that but it's not working and create record whereas i am rollbacking on any sort of exception happen . Can you give little guide on that in your next video would be great 🙂
Not sure if I would add anything mode useful than default Laravel docs in this case.
It's also about debugging your own personal code, I can't do the debugging for you, sorry.
Why are we querying the products separately in the first step? Can't we use $cart to get the products as we already have used eager loading to get the related products?
$products = $cart->pluck('product.quantity_left', 'product.id')->all();
Hello Sir. I have a question. Is storing cart data in database better than storing data in session?
Personal preference.
Hi
Sir can you please guide me for, how can I update the cart items for example you have make like everytime you make a cart update items. Some items will be added and some should delete from cart for some increase or decrease the quantity. Will you please guide me how to do so. I can share example for my question also let me know if it's required.
Create a video about design pattern in Laravel framework please
Which design pattern? There are dozens of them.
Also, look at the examples in my laravelexamples.com - section "Patterns"
@@LaravelDaily repository and service
Search the channel: ua-cam.com/channels/TuplgOBi6tJIlesIboymGA.htmlsearch?query=service
how to add progress bar while importing excel
Nice videos every day, are you thinking in create new courses in your teachable page ?
Yes, I'm just taking a small summer break, but the next plan is the course about flutter mobile apps with Laravel API, coming in September.
That would be awesome
How to dynamically switch the database in laravel hoping for your reply? 🥺
I tell that anyone of age of comprehension CAN become a programmer, but if you cannot grasp the concept of using Google when it is free and available for most (even alt search engines will help you greatly), then you will struggle too much for your own good (but you'll help better devs with getting a job fixing your errors, sort of a 'win - win' situation; call me names, I don't care - that's the truth).
I advise you to take your comment, cut off the part of "hoping for your reply" and put it in the search input on Google. First result, done.
Do your own f.. research & RTFM!
Please I need your help in a task to get a job the task is about appointments
can you share the code for this video?
How would you handle race condition in this example? If 2 people are buying the same product at same exact time wouldn't this cause problem?
For race condition, I would introduce the "reservation" of the products and then release the reservations after they finalize the purchase or become available if the transaction isn't complete in, like, 15 minutes.
Hey I like your video can u make a tutorial for running your project on .test
For that, I just use Laravel Valet locally, and it does it automatically for me
@@LaravelDaily thanks
Uses with('product'), doesn't use it, loads it in the line below again :'D
Can you share the code, please?
You can skip querying products, you can use Cart products relationship for everything, can't you?
One query to find product, then decrement quantity, all in a loop.
Incrementing order total quantity is also in loop? Not good.
And you can make $cart->delete(), since you already have it.