直到昨天,它的工作都完美无缺,但是我删除了一些未使用的类,现在laravel的自动装配功能无法解决类型提示的依赖关系。
我在AppServiceProvider.php中声明了服务类的各种绑定,应该通过自动装配来解决依赖关系,但没有。
我留下了AppServiceProvider.php的示例代码和一个ProductoService.php类的代码
我在这里想念的是什么?预先感谢!
Type error: Too few arguments to function App\Services\ProductoService::__construct(), 0 passed in /home/eznb/Documentos/osiris/app/Providers/AppServiceProvider.php on line 44 and exactly 1 expected
namespace App\Providers;
use App\Services\CajaService;
use App\Services\PrecioService;
use App\Services\ProductoService;
use App\Services\ServicioService;
use App\Services\TrabajoService;
use App\Services\TurnoService;
use Calendar;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
view()->composer('*', function ($view) {
$event_list = [];
$calendar_details = Calendar::addEvents($event_list);
$view->with('calendar_details', $calendar_details);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(PrecioService::class, function ($app) {
return new PrecioService();
});
$this->app->bind(ProductoService::class, function ($app) {
return new ProductoService();
});
$this->app->bind(ServicioService::class, function ($app) {
return new ServicioService();
});
$this->app->bind(CajaService::class, function ($app) {
return new CajaService();
});
$this->app->bind(TrabajoService::class, function ($app) {
return new TrabajoService();
});
$this->app->bind(TurnoService::class, function ($app) {
return new TurnoService();
});
}
}
namespace App\Services;
use App\Producto;
use App\Services\PrecioService;
class ProductoService
{
protected $precio_service;
public function __construct(PrecioService $precio_service)
{
$this->precio_service = $precio_service;
}
.
.
.
some more core
.
.
.
请将您的AppServiceProvider.php更改为以下
namespace App\Providers;
use App\Services\CajaService;
use App\Services\PrecioService;
use App\Services\ProductoService;
use App\Services\ServicioService;
use App\Services\TrabajoService;
use App\Services\TurnoService;
use Calendar;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
view()->composer('*', function ($view) {
$event_list = [];
$calendar_details = Calendar::addEvents($event_list);
$view->with('calendar_details', $calendar_details);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(PrecioService::class, function ($app) {
return new PrecioService();
});
$this->app->bind(ProductoService::class, function ($app) {
return new ProductoService($app[PrecioService::class]); // Here i made the change as you ProductoService constructort has as its dependency
});
$this->app->bind(ServicioService::class, function ($app) {
return new ServicioService();
});
$this->app->bind(CajaService::class, function ($app) {
return new CajaService();
});
$this->app->bind(TrabajoService::class, function ($app) {
return new TrabajoService();
});
$this->app->bind(TurnoService::class, function ($app) {
return new TurnoService();
});
}