服务提供商提出错误。它提供了其类的没有发现
问题描述:
我想测试我自己的哑分量与服务供应商,但我得到这个错误:服务提供商提出错误。它提供了其类的没有发现
FatalErrorException in ProviderRepository.php line 146: Class 'Luismartin\Notificador\Notificador' not found
这是Notificador级,位于在供应商/ luismartin/notificador/SRC/Notificador.php(我跑了作曲家转储自动加载创建后):
<?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...
}
}
及其服务提供商,置于应用程序/供应商/ NotificadorServiceProvider.php:
'providers' => [
//...,
Luismartin\Notificador\Notificador::class,
],
最后,控制器方法,其中我:
<?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());
});
}
}
已在配置\ app.php添加试图使用Notificador组件:
private function notificar($mensaje)
{
$admin = User::where('name', 'admin')->first();
$notificador = App::make('Notificador');
$notificador->notificar($admin, $mensaje);
}
我还应该做什么?
我也尝试删除composer.lock并运行作曲家更新。以下是它在最后显示的内容:
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.....
答
我发现了该错误。在服务提供商列表中声明组件类时,我对该组件类感到困惑:
'providers' => [
//...,
App\Providers\NotificadorServiceProvider::class,
],
现在可以工作了。
删除您的composer.lock文件并再次运行作曲家更新。还要将app.php文件中的位置更改为'App/Providers/NotificadorServiceProvider :: class'(在作曲者更新之前执行此操作) –
该软件包是如何安装的?作曲家?如果是这样,请使用其他代码将服务提供商保留在供应商文件夹中 –
我已经删除了composer.lock并运行了作曲家更新。它还显示与我的课程相关的错误。我已经在上面添加了它。 –