前台品牌列表和品牌商品列表
This commit is contained in:
parent
3cddcd8ce8
commit
cdbd42c464
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Beike\Shop\Http\Controllers;
|
||||
|
||||
use Beike\Models\Product;
|
||||
use Beike\Repositories\BrandRepo;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Beike\Shop\Http\Resources\ProductDetail;
|
||||
use Beike\Shop\Http\Resources\ProductList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BrandController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$brands = BrandRepo::listGroupByFirst();
|
||||
$data = [
|
||||
'brands' => $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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Beike\Shop\Http\Controllers;
|
||||
|
||||
use Beike\Models\Product;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Beike\Shop\Http\Resources\ProductDetail;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ManufacturerController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$addresses = AddressRepo::listByCustomer(current_customer());
|
||||
$data = [
|
||||
'countries' => 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* BrandDetail.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue