The art of debugging is very important as it could save you lot of time and headaches. Tools used
- Laravel
- Visual Studio Code(VSCode)
- Xdebug
- PHP Debug extension for Visual Studio Code (Debug support for PHP with Xdebug)
- Xdebug helper(Browser Extension)
Am going to skip the installation of this tools as once you encounter the "Class not found exception" then you have passed the installation stage.
After installing PHP debug extension and accessing its launch.json file from .vscode directory. You will see 3 different settings in configurations which you must take note of base on the name.
Without the use of imported Classes in your debugging script you are likely not to experience any issues with any of these configurations. eg. using name: Launch currently open script
For Laravel application the entry point is the index.php file which is inside the public folder. These file loads all the required files to handle request from the browser. So when we use the browser extension debug helper together with our break points we wont' have the exception: "Class .... not Found"
The Solution
Change the debug configurations option name to Listen for Xdebug
And enable debugger helper extension in the browser.
After enabling the debug helper extension and refreshing the page again we see that the page keeps loading and never stops because our first break point has been hit awaiting our next action
We can see that our $user variable is not initialized yet from the VARIABLES SECTION.
When we click on continue to the next break point, we now see the $user variable being initialize which we can now inspect.
Congratulations!!!!. Class not found exception during debugging in laravel is sorted. Let me know what you think as sharing helps us learn better.
Top comments (0)