I'm trying to test a dummy component of my own with a Service Provider, but I'm getting this error:
FatalErrorException in ProviderRepository.php line 146: Class 'Luismartin\Notificador\Notificador' not found
This is the Notificador class, located in vendor/luismartin/notificador/src/Notificador.php (I ran a composer dump-autoload after creating it):
<?php
namespace Luismartin\Notificador;
use Illuminate\Foundation\Auth\User;
use Illuminate\Mail\Mailer;
class Notificador
{
private $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function notificar(User $usuario, $mensaje)
{
// notifier actions...
}
}
Its Service Provider, placed in app/Providers/NotificadorServiceProvider.php:
<?php
namespace App\Providers;
use Illuminate\Mail\Mailer;
use Illuminate\Support\ServiceProvider;
use Luismartin\Notificador\Notificador;
class NotificadorServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('Notificador', function() {
return new Notificador(new Mailer());
});
}
}
It has been added in config\app.php:
'providers' => [
//...,
Luismartin\Notificador\Notificador::class,
],
And finally, the controller method in which I'm trying to use the Notificador component:
private function notificar($mensaje)
{
$admin = User::where('name', 'admin')->first();
$notificador = App::make('Notificador');
$notificador->notificar($admin, $mensaje);
}
What else should I do?
I've also tried deleting composer.lock and running composer update. Here's what it displays at the end:
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
PHP Fatal error: Class 'Luismartin\Notificador\Notificador' not found in /home/vagrant/Code/helpdesk/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository
PHP Stack trace.....
App/Providers/NotificadorServiceProvider::class
(do this before composer update) – Mike Barwick