Creating Local Database0:00
Here's what I love. All of our tests are currently passing, and yet, we haven't even created a local database yet. We haven't needed to. Let's do that now. I'm going to go to my .env file, and right up here, I'll stick with MySQL, even though we don't need it, SQLite would be entirely fine. For the database, I'll call it nstock, and let's create that now. And TablePlus, I'll add one here. There we go.
Migrating and Seeding Data0:27
And TablePlus, I'll add one here. There we go. Next, let's migrate my database. And if I switch back and give it a refresh, there we go. So we have users, retailers, stock, products, etc. For a product, we'll stick with that Nintendo Switch Neon idea. Next, I'll set up a retailer, Best Buy. And now, we need stock for that product at that retailer. Now, of course, we could do it directly here, or we can do it with Eloquent. Let's find our retailer and our product.
Adding Stock via Eloquent0:57
Now, of course, we could do it directly here, or we can do it with Eloquent. Let's find our retailer and our product. And then you'll remember, on our retailer model, we have this method addStock, so we'll do that now. Retailer addStock for this product, and we'll set that up. The current price, I'm going to fake this. I'm going to say it's $399, just to show you when it changes after being tracked. The SKU, if I switch back, is right here. The URL, I should have that in my clipboard. And for the nstock field, once again, we'll set that to true.
Running Track Command1:37
The URL, I should have that in my clipboard. And for the nstock field, once again, we'll set that to true. All right, so let's give that a run. And now if I go back to TablePlus, there we go. So now, let's run the command to update that stock. If I run php artisan and scroll up, it'll be right here. You can view the help and get started. php artisan track. Now, before I run that, remember, what's going to happen if I go to the track command is it'll fetch all of the products, and then for each one, it'll track it.
Explaining Tracking and Results2:06
Now, before I run that, remember, what's going to happen if I go to the track command is it'll fetch all of the products, and then for each one, it'll track it. A product is tracked by looking at all the stock for that product across all retailers. And for each one, that stock, or rather that stock availability, will be checked, and then we update our local database with the latest information. So let's give it a shot. We run it. Now if I come back to TablePlus, notice we set the price to $399 and nstock to true. But if I give it a refresh, okay. Now the latest information is $299 and it's not in stock.