I’m working on a Laravel 10 project and ran into a Class not found error when executing an artisan command.
Goal: I want to create a custom artisan command that fetches data from the database.
Problem: When I run
php artisan fetch:data
I get the following error:
Target class [AppConsoleCommandsFetchData] does not exist.
What I’ve tried
-
Checked that my class
FetchData.phpexists underapp/Console/Commands/. -
Verified that the namespace is correct (
namespace AppConsoleCommands;). -
Registered the command inside
app/Console/Kernel.phpunder$commands. -
Ran
composer dump-autoload.
Expected result
The artisan command should run successfully and fetch the data.
Actual result
I keep getting the Class not found error.
Error message:
In Container.php line 895:
Target class [AppConsoleCommandsFetchData] does not exist.
What could be the reason for this error and how can I fix it?