Laravel Debugging Scenario 0:00Now that you understand how to debug a single PHP script, how do we move up to something a little more real world, where you're actually debugging a full application. So here, in this example, using Laravel, you can see that we've set up an articles controller. It looks like we pull in some kind of repository, we fetch a bunch of records from that repository, and then we load a simple hello view and pass through the articles. Now, within that view, you can see that we do nothing more than filter through this array, and for each one, we simply echo out the value within a list item. So pretty basic stuff, right? Now, I feel like this should work, but the problem is, when I run it in the browser, I get this error exception here. Invalid arguments supplied to the foreach. So how do I go about debugging this? Well, if I switch back using Command-E, the most common practice is to do something as simple as dd articles and just figure out what Configuring Web Debugger 0:44the foreach. So how do I go about debugging this? Well, if I switch back using Command-E, the most common practice is to do something as simple as dd articles and just figure out what you're getting in return. So if I refresh it, we can see, oh, for some reason null is being returned here, and then you can move on and maybe add a var dump somewhere else within the call stack to figure out where the error is. But instead, why don't we simply use xdebug to figure this out? Now, I will go to run, and we need to edit our configurations. This time, rather than a PHP script, I want a full web application debugger. Now, in terms of the server, you'll see we have nothing set up. So we can do that right now. I will simply call this Laravel, and I'm going to set the host equal to whatever server I'm running. In this case, it's at localhost port 8000, and I am using xdebug. And that should do it. So let's apply it. And now, for the start URL, let's set Setting Breakpoints and Rerun 1:28set the host equal to whatever server I'm running. In this case, it's at localhost port 8000, and I am using xdebug. And that should do it. So let's apply it. And now, for the start URL, let's set it to our articles collection. Okay, and we'll give it a name of demo or Laravel or whatever you want to call it. So we apply that. And really, that's all we have to do. So now I can run and debug. But now this time, you can see that the browser actually loads. Now, in this case, though, we didn't set any breakpoints. So once again, it just fired through the whole thing and never hit a stop. So let's stop it. And we want to figure out why articles is returning null, right? So let's set a breakpoint right here and rerun it. Okay, so this time, if I switch back, you can see we haven't gotten to that point where we loaded a view and a response. So it's sort of hovering right now. At this point, we can dig in, view the entire call stack here, figure out what we currently Stepping Into Repository Call 2:18we haven't gotten to that point where we loaded a view and a response. So it's sort of hovering right now. At this point, we can dig in, view the entire call stack here, figure out what we currently have registered. But I really want to figure out why articles is being set to null. So let's step into this call right here. Step in. And here you can see I have a little bit of pseudocode just to simulate something where maybe we end up returning null. So now when we're debugging, we can see, oh, so this is firing and I didn't expect that to happen. That means though I expected this array to be returned, that turned out not to be the case. So I'm done here. Let's step out. And now we can see, yep, articles is being set to null. So I know what to do to fix this. One quick note on this, though, by the way, if you ever need to, you can update these values in real time. So for example, if I right click and choose set value, let's set this to that original Modifying Values During Debug 3:04One quick note on this, though, by the way, if you ever need to, you can update these values in real time. So for example, if I right click and choose set value, let's set this to that original array. And now if we finish up, and if I switch back over to the browser, you can see that it's reflecting that new value that we just applied. So yeah, that's basically all there is to it. So now you have all the power and flexibility in the world to debug your applications using phpStorm and XDebug.