我正在使用laravel Modules和Repository。我在App和Controller模块中创建了Repository。但是当控制器调用Repository时,它会报告" ReflectionException 类Modules \ Product \ Http \ Controllers \ ProductEntryRepository不存在"。
但App \ Reppsitory中的ProductEntryRepository但在Controlller中出错。
namespace Modules\Product\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use \App\Repositories\ProductCategoryRepository;
use \App\Repositories\ProductCategoryEntryRepository;
class ProductCategoryController extends Controller
{
/**
* @var PostRepository
*/
protected $request;
protected $product_category;
protected $product_category_entry;
public function __construct(Request $request, ProductCategoryRepository $product_category, ProductEntryRepository $product_category_entry){
$this->request = $request;
$this->product_category = $product_category;
$this->product_category_entry = $product_category_entry;
}
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
return view('product::index');
}
答案 0 :(得分:1)
您只需在控制器顶部添加use \App\Repositories\ProductEntryRepository;
即可:)
namespace Modules\Product\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use \App\Repositories\ProductCategoryRepository;
use \App\Repositories\ProductCategoryEntryRepository;
use \App\Repositories\ProductEntryRepository;
class ProductCategoryController extends Controller
{
//......
}
或者我认为你的意思是ProductCategoryEntryRepository
而不是ProductEntryRepository
在构造!!
public function __construct(Request $request, ProductCategoryRepository $product_category, ProductCategoryEntryRepository $product_category_entry){
$this->request = $request;
$this->product_category = $product_category;
$this->product_category_entry = $product_category_entry;
}