I am going through a laravel tutorial and the section I am stuck on is called "The Service Container" Basically I just grab a environment variable and spit it out to the page with a dd() die and dump. However I get a class not found
error. I know it must be a small bug, but cant quite figure it out. I tried running composer dump-autoload
with no luck.
Here is my code
routes/web.php
App::bind('App\Billing\Stripe', function(){
return new \App\Billing\Stripe(config('services.stripe.secret'));
});
$stripe = App::make('App\Billing\Stripe');
dd($stripe);
app/billing/Stripe.php
namespace App\Billing;
class Stripe{
protected $key;
public function __construct($key){
$this->key = $key;
}
}
There is no need here for dump-autoload because you're creating a new namespace inside psr-4 confiugred folder app
.
The solution is to rename the folder billing
to a capital case, because laravel uses composer autoload following psr-4 standard which states that namespace matches the folder name in a case sensitive way.
Note : there are alternative autoloading schemes provided by composer that may need composer dump-autoload
or editing composer.json
when a new file is created