我正在尝试使用存储库,但收到此错误:
Class App'Repositories'CategoryRepository does not exist
这是我的类别存储库.php
<?php
namespace App'Repositories;
class SubCate
{
/**
* Get all of the tasks for a given user.
*
* @param User $user
* @return Collection
*/
public function getCategories(){
$categories='App'category::where('parent_id',0)->get();//united
$categories=$this->addRelation($categories);
return $categories;
}
}
?>
这是我的控制器:
<?php
namespace App'Http'Controllers;
use Illuminate'Http'Request;
use App'Http'Requests;
use App'Http'Controllers'Controller;
use DB;
use App'Product;
use App'Category;
use App'Repositories'CategoryRepository;
class ProductController extends Controller
{
//
public function __construct(CategoryRepository $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
}
public function index(Request $request)
{
$subcate = new SubCate;
try {
$allSubCategories=$subcate->getCategories();
} catch (Exception $e) {
//no parent category found
}
return view('welcome', [
'allSubCategories' => $allSubCategories,
]);
}
}
怎么了?
您的类别存储库类名是
class SubCate
但您正在使用
use App'Repositories'CategoryRepository;
.
因此,请将类名更改为CategoryRepository