品牌由manufacturer改为brand
This commit is contained in:
parent
db43cfa8a3
commit
3cddcd8ce8
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* ManufacturerController.php
|
||||
* BrandController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
|
|
@ -11,32 +11,32 @@
|
|||
|
||||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
use Beike\Repositories\ManufacturerRepo;
|
||||
use Beike\Repositories\BrandRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ManufacturerController extends Controller
|
||||
class BrandController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$manufacturers = ManufacturerRepo::list($request->only('name', 'first', 'status'));
|
||||
$brands = BrandRepo::list($request->only('name', 'first', 'status'));
|
||||
$data = [
|
||||
'manufacturers' => $manufacturers,
|
||||
'brands' => $brands,
|
||||
];
|
||||
|
||||
return view('admin::pages.manufacturers.index', $data);
|
||||
return view('admin::pages.brands.index', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$manufacturer = ManufacturerRepo::create($request->all());
|
||||
return json_success("创建成功", $manufacturer);
|
||||
$brand = BrandRepo::create($request->all());
|
||||
return json_success("创建成功", $brand);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $customerId, int $id)
|
||||
{
|
||||
$manufacturer = ManufacturerRepo::update($id, $request->all());
|
||||
$brand = BrandRepo::update($id, $request->all());
|
||||
|
||||
return json_success("成功修改", $manufacturer);
|
||||
return json_success("成功修改", $brand);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $customerId, int $addressId)
|
||||
|
|
@ -38,7 +38,7 @@ Route::prefix($adminName)
|
|||
Route::post('design/builder/preview', [Controllers\DesignController::class, 'preview'])->name('design.module.preview');
|
||||
|
||||
Route::resource('files', Controllers\FileController::class);
|
||||
Route::resource('manufacturers', Controllers\ManufacturerController::class);
|
||||
Route::resource('brands', Controllers\BrandController::class);
|
||||
|
||||
Route::get('file_manager', [Controllers\FileManagerController::class, 'index'])->name('file_manager.index');
|
||||
Route::get('file_manager/files', [Controllers\FileManagerController::class, 'getFiles'])->name('file_manager.get_files');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Manufacturer.php
|
||||
* Brand.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
|
|
@ -14,7 +14,7 @@ namespace Beike\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Manufacturer extends Base
|
||||
class Brand extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
@ -24,5 +24,10 @@ class Manufacturer extends Base
|
|||
{
|
||||
return $this->hasMany(Zone::class);
|
||||
}
|
||||
|
||||
public function products() :HasMany
|
||||
{
|
||||
return $this->hasMany(Product::Class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +42,11 @@ class Product extends Base
|
|||
return $this->hasOne(ProductSku::Class)->where('is_default', 1);
|
||||
}
|
||||
|
||||
public function manufacturer()
|
||||
{
|
||||
return $this->hasOne(Brand::Class, 'id', 'manufacturer_id');
|
||||
}
|
||||
|
||||
public function getPriceFormattedAttribute(): string
|
||||
{
|
||||
return '$' . $this->price;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* ManufacturerRepo.php
|
||||
* BrandRepo.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Manufacturer;
|
||||
use Beike\Models\Brand;
|
||||
|
||||
class ManufacturerRepo
|
||||
class BrandRepo
|
||||
{
|
||||
/**
|
||||
* 创建一个记录
|
||||
|
|
@ -22,26 +22,26 @@ class ManufacturerRepo
|
|||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$manufacturer = Manufacturer::query()->create($data);
|
||||
return $manufacturer;
|
||||
$brand = Brand::query()->create($data);
|
||||
return $brand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $manufacturer
|
||||
* @param $brand
|
||||
* @param $data
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function update($manufacturer, $data)
|
||||
public static function update($brand, $data)
|
||||
{
|
||||
if (!$manufacturer instanceof Manufacturer) {
|
||||
$manufacturer = Manufacturer::query()->find($manufacturer);
|
||||
if (!$brand instanceof Brand) {
|
||||
$brand = Brand::query()->find($brand);
|
||||
}
|
||||
if (!$manufacturer) {
|
||||
throw new \Exception("品牌id {$manufacturer} 不存在");
|
||||
if (!$brand) {
|
||||
throw new \Exception("品牌id {$brand} 不存在");
|
||||
}
|
||||
$manufacturer->update($data);
|
||||
return $manufacturer;
|
||||
$brand->update($data);
|
||||
return $brand;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -50,7 +50,7 @@ class ManufacturerRepo
|
|||
*/
|
||||
public static function find($id)
|
||||
{
|
||||
return Manufacturer::query()->find($id);
|
||||
return Brand::query()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,9 +59,9 @@ class ManufacturerRepo
|
|||
*/
|
||||
public static function delete($id)
|
||||
{
|
||||
$manufacturer = Manufacturer::query()->find($id);
|
||||
if ($manufacturer) {
|
||||
$manufacturer->delete();
|
||||
$brand = Brand::query()->find($id);
|
||||
if ($brand) {
|
||||
$brand->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ class ManufacturerRepo
|
|||
*/
|
||||
public static function list($data)
|
||||
{
|
||||
$builder = Manufacturer::query();
|
||||
$builder = Brand::query();
|
||||
|
||||
if (isset($data['name'])) {
|
||||
$builder->where('name', 'like', "%{$data['name']}%");
|
||||
|
|
@ -88,11 +88,11 @@ class ManufacturerRepo
|
|||
|
||||
public static function listGroupByFirst()
|
||||
{
|
||||
$manufacturers = Manufacturer::query()->where('status', true)->get();
|
||||
$brands = Brand::query()->where('status', true)->get();
|
||||
|
||||
$results = [];
|
||||
foreach ($manufacturers as $manufacturer) {
|
||||
$results[$manufacturer->first][] = $manufacturer;
|
||||
foreach ($brands as $brand) {
|
||||
$results[$brand->first][] = $brand;
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
|
@ -13,7 +13,7 @@ class CreateManufacturers extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('manufacturers', function (Blueprint $table) {
|
||||
Schema::create('brands', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->char('first');
|
||||
|
|
@ -23,7 +23,7 @@ class CreateManufacturers extends Migration
|
|||
$table->timestamps();
|
||||
});
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->unsignedInteger('manufacturer_id')->after('id')->index();
|
||||
$table->unsignedInteger('brand_id')->after('id')->index();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -34,9 +34,9 @@ class CreateManufacturers extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('manufacturers');
|
||||
Schema::dropIfExists('brands');
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropColumn('manufacturer_id');
|
||||
$table->dropColumn('brand_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
@section('title', '品牌管理')
|
||||
|
||||
@section('content')
|
||||
<div id="manufacturer-app" class="card">
|
||||
<div id="brand-app" class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between my-4">
|
||||
<a href="{{ admin_route('currencies.create') }}" class="btn btn-primary">创建</a>
|
||||
|
|
@ -20,16 +20,16 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($manufacturers as $manufacturer)
|
||||
@foreach ($brands as $brand)
|
||||
<tr>
|
||||
<td>{{ $manufacturer['id'] }}</td>
|
||||
<td>{{ $manufacturer['name'] }}</td>
|
||||
<td>{{ $manufacturer['logo'] }}</td>
|
||||
<td>{{ $manufacturer['sort_order'] }}</td>
|
||||
<td>{{ $manufacturer['status'] }}</td>
|
||||
<td>{{ $brand['id'] }}</td>
|
||||
<td>{{ $brand['name'] }}</td>
|
||||
<td>{{ $brand['logo'] }}</td>
|
||||
<td>{{ $brand['sort_order'] }}</td>
|
||||
<td>{{ $brand['status'] }}</td>
|
||||
<td>
|
||||
<a class="btn btn-outline-secondary btn-sm"
|
||||
href="{{ admin_route('manufacturers.edit', [$manufacturer['id']]) }}">编辑</a>
|
||||
href="{{ admin_route('brands.edit', [$brand['id']]) }}">编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
Loading…
Reference in New Issue