diff --git a/beike/Models/Brand.php b/beike/Models/Brand.php index 50d4024b..5ff054fa 100644 --- a/beike/Models/Brand.php +++ b/beike/Models/Brand.php @@ -20,11 +20,6 @@ class Brand extends Base protected $fillable = ['name', 'country_id', 'code', 'sort_order', 'status']; - public function zones(): HasMany - { - return $this->hasMany(Zone::class); - } - public function products() :HasMany { return $this->hasMany(Product::Class); diff --git a/beike/Repositories/BrandRepo.php b/beike/Repositories/BrandRepo.php index 5d7485ef..fd09d7b1 100644 --- a/beike/Repositories/BrandRepo.php +++ b/beike/Repositories/BrandRepo.php @@ -12,6 +12,7 @@ namespace Beike\Repositories; use Beike\Models\Brand; +use Beike\Shop\Http\Resources\BrandDetail; class BrandRepo { @@ -92,7 +93,7 @@ class BrandRepo $results = []; foreach ($brands as $brand) { - $results[$brand->first][] = $brand; + $results[$brand->first][] = (new BrandDetail($brand))->jsonSerialize(); } return $results; diff --git a/beike/Shop/Http/Controllers/BrandController.php b/beike/Shop/Http/Controllers/BrandController.php new file mode 100644 index 00000000..206b2557 --- /dev/null +++ b/beike/Shop/Http/Controllers/BrandController.php @@ -0,0 +1,34 @@ + $brands, + ]; + + return view('brand/list', $data); + } + + public function show(int $id) + { + $products = BrandRepo::find($id)->products()->paginate(20); + + $data = [ + 'products' => ProductList::collection($products)->jsonSerialize(), + ]; + + return view('brand/info', $data); + } +} diff --git a/beike/Shop/Http/Controllers/ManufacturerController.php b/beike/Shop/Http/Controllers/ManufacturerController.php deleted file mode 100644 index c71da2fb..00000000 --- a/beike/Shop/Http/Controllers/ManufacturerController.php +++ /dev/null @@ -1,33 +0,0 @@ - CountryRepo::all(), - 'addresses' => AddressResource::collection($addresses), - ]; - - return view('account/address', $data); - } - - public function show(Request $request, Product $product) - { - $product = ProductRepo::getProductDetail($product); - - $data = [ - 'product' => (new ProductDetail($product))->jsonSerialize(), - ]; - - return view('product', $data); - } -} diff --git a/beike/Shop/Http/Resources/BrandDetail.php b/beike/Shop/Http/Resources/BrandDetail.php new file mode 100644 index 00000000..5a188729 --- /dev/null +++ b/beike/Shop/Http/Resources/BrandDetail.php @@ -0,0 +1,28 @@ + + * @created 2022-07-28 15:33:06 + * @modified 2022-07-28 15:33:06 + */ + +namespace Beike\Shop\Http\Resources; + +use Illuminate\Http\Resources\Json\JsonResource; + +class BrandDetail extends JsonResource +{ + public function toArray($request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'logo' => image_resize($this->logo), + 'sort_order' => $this->sort_order, + 'first' => $this->first, + ]; + } +} diff --git a/beike/Shop/Routes/shop.php b/beike/Shop/Routes/shop.php index 1e4fc1e4..08b09a23 100644 --- a/beike/Shop/Routes/shop.php +++ b/beike/Shop/Routes/shop.php @@ -2,6 +2,7 @@ use Beike\Models\Customer; use Beike\Shop\Http\Controllers\Account\WishlistController; +use Beike\Shop\Http\Controllers\BrandController; use Illuminate\Support\Facades\Route; use Beike\Shop\Http\Controllers\ZoneController; use Beike\Shop\Http\Controllers\CartController; @@ -25,6 +26,9 @@ Route::prefix('/') ->group(function () { Route::get('/', [HomeController::class, 'index'])->name('home.index'); + Route::get('brands', [BrandController::class, 'index'])->name('brands.index'); + Route::get('brands/{id}', [BrandController::class, 'show'])->name('brands.show'); + Route::get('carts', [CartController::class, 'index'])->name('carts.index'); Route::post('carts', [CartController::class, 'store'])->name('carts.store'); Route::get('carts/mini', [CartController::class, 'miniCart'])->name('carts.mini');