you have to run the dump-autoload command which won't download anything new, but looks for all of the classes it needs to include again. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php)
Why i have to dump-autoload every time i create a new class?
Hello there i am new to laravel and i am following the this video https://laracasts.com/series/whip-monstrous-code-into-shape/episodes/2?autoplay=true and i have created a new usecase inside App\UseCases\PurchasePodcast.php the code of the file is this one:
namespace App\UseCases;
Class PurchasePodcast extends UseCases
{
public function handle()
{
$this->preparePurchase()
->sendEmail();
}
private function preparePurchase()
{
echo "<pre>";
print_r('prepering the purchase');
echo "</pre>";
return $this;
}
private function sendEmail()
{
echo "<pre>";
print_r('send an email with their invoice');
echo "</pre>";
return $this;
}
}
then i have created the UseCase class and the code is this one:
namespace App\UseCases;
abstract class UseCases
{
public static function perform()
{
return (new static)->handle();
}
abstract public function handle();
}
and why i tried to run the application/website i got an error that it cannot find the UseCase class. Then i have to run composer dump-autoload and restart the server and then the website is working fine again and was able to find the UseCase class, but my question is why i have to run composer dump-autoload everytime i create manually a new class?
I'm using laravel valet. I don't need to run serve at all) it is always up) and recommend you to switch to valet if you are on mac or linux.
Please or to participate in this conversation.