Laravel错误:目标[IlluminateViewEnginesEngineInterface]不可实例


Laravel error: Target [IlluminateViewEnginesEngineInterface] is not instantiable

我正在创建一个抽象类,它将使用Laravel的View类获取视图的内容。但是在尝试从扩展它的类运行方法时,我收到以下错误:

Illuminate ' Container ' BindingResolutionException
Target [Illuminate'View'Engines'EngineInterface] is not instantiable.

这是我的代码:

pdf报告.php

use Illuminate'View'View as View;
abstract class PdfReport {
  private $view;
  function __construct(View $view)
  {
      $this->view = $view;
  }
  public function render($reportView, $report)
  {
      $this->view->make('report.pdf.' . $reportView, ['report' => $report])->render();
  }
}

EslReport.php

<?php namespace Reports'PdfReports;
class EslPdfReport extends PdfReport {
    public function renderReport($report)
    {
        return $this->render('esl', $report);
    }
}

然后我在路由中运行我的代码.php用于测试目的,如下所示:

use Reports'PdfReports'EslPdfReport;
Route::get('pdftest', array(    
    'as' => 'pdftest',
        function(){
            $eslReport = App::make('Reports'PdfReports'EslPdfReport');
            $eslReport->renderReport(EslReport::find(1));
        }
));

不太明白我是否在抽象类中视图的依赖注入中做错了什么,这对我来说都是非常新的概念,所以任何帮助将不胜感激。

我也在 laracasts 论坛上问了这个问题,如果它有帮助:https://laracasts.com/discuss/channels/general-discussion/confusion-about-constructors-in-abstract-classes

而不是Illuminate'View'View你需要注入Illuminate'View'Factory

use Illuminate'View'Factory as View;

下面是外观类的参考,以及使用 DI 时需要使用的实际基础类