Php Laravel-应用程序中的控制器调用存储库
我正在尝试laravel模块和存储库。我在应用程序中创建了存储库,在模块中创建了控制器。但当控制器调用存储库时,它会报告“ReflectionException” 类模块\Product\Http\Controllers\ProductEntryRepository不存在” 但应用程序中的ProductEntryRepository\Reppsitory但控制器中存在错误。Php Laravel-应用程序中的控制器调用存储库,php,laravel,laravel-5,repository,Php,Laravel,Laravel 5,Repository,我正在尝试laravel模块和存储库。我在应用程序中创建了存储库,在模块中创建了控制器。但当控制器调用存储库时,它会报告“ReflectionException” 类模块\Product\Http\Controllers\ProductEntryRepository不存在” 但应用程序中的ProductEntryRepository\Reppsitory但控制器中存在错误。 您只需添加use\App\Repositories\ProductEntryRepository位于控制器顶部:) 或者我
您只需添加
use\App\Repositories\ProductEntryRepository代码>位于控制器顶部:)
或者我想你的意思是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;
}
我可以从任何App\Http\Resources类调用repository类吗?可以,您可以将其称为Laravel,它将为您解决依赖关系;)
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
{
//......
}
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;
}