fixed home page
This commit is contained in:
parent
5aa46f026b
commit
85cbdc7b97
|
|
@ -3,16 +3,15 @@
|
|||
namespace Beike\Shop\Http\Controllers;
|
||||
|
||||
use Beike\Models\Category;
|
||||
use Beike\Shop\Repositories\CategoryRepo;
|
||||
use Plugin\Guangda\Seller\Models\Product;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$categories = Category::with('description')->where('active', 1)->get();
|
||||
|
||||
$data = [
|
||||
'categories' => $categories,
|
||||
'categories' => CategoryRepo::getTwoLevelCategories(),
|
||||
];
|
||||
|
||||
return view('home', $data);
|
||||
|
|
|
|||
|
|
@ -14,9 +14,14 @@ class CategoryItem extends JsonResource
|
|||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
$item = [
|
||||
'id' => $this->id,
|
||||
'name' => $this->description->name ?? ''
|
||||
'name' => $this->description->name ?? '',
|
||||
|
||||
];
|
||||
if ($this->children) {
|
||||
$item['children'] = self::collection($this->children);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,27 @@
|
|||
namespace Beike\Shop\Repositories;
|
||||
|
||||
use Beike\Models\Category;
|
||||
use Beike\Shop\Http\Resources\CategoryItem;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class CategoryRepo
|
||||
{
|
||||
/**
|
||||
* 获取所有分类
|
||||
*/
|
||||
public static function getTwoLevelCategories()
|
||||
{
|
||||
$topCategories = Category::query()
|
||||
->from('categories as c')
|
||||
->with(['description', 'children.description'])
|
||||
->where('parent_id', 0)
|
||||
->get();
|
||||
|
||||
return CategoryItem::collection($topCategories);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取产品分类列表
|
||||
*
|
||||
|
|
@ -25,7 +41,7 @@ class CategoryRepo
|
|||
*/
|
||||
public static function list(array $filter = [])
|
||||
{
|
||||
$keyword = $filter['keyword']??'';
|
||||
$keyword = $filter['keyword'] ?? '';
|
||||
$builder = Category::query()->with(['description']);
|
||||
if ($keyword) {
|
||||
// $builder->whereExists('name')
|
||||
|
|
|
|||
Loading…
Reference in New Issue