获取商品名称;获取分类名称
This commit is contained in:
parent
41f163edf1
commit
b9ad5d7c10
|
|
@ -7,6 +7,7 @@ use Beike\Admin\Http\Resources\CategoryResource;
|
|||
use Beike\Admin\Repositories\CategoryRepo;
|
||||
use Beike\Models\Category;
|
||||
use Beike\Admin\Services\CategoryService;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoryController extends Controller
|
||||
|
|
@ -46,6 +47,13 @@ class CategoryController extends Controller
|
|||
return $this->save($request, $category);
|
||||
}
|
||||
|
||||
public function name(int $id)
|
||||
{
|
||||
$name = CategoryRepo::getName($id);
|
||||
|
||||
return json_success('获取成功', $name);
|
||||
}
|
||||
|
||||
protected function form(Request $request, Category $category = null)
|
||||
{
|
||||
if ($category) {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ namespace Beike\Admin\Http\Controllers;
|
|||
use Beike\Admin\Http\Resources\ProductResource;
|
||||
use Beike\Admin\Repositories\CategoryRepo;
|
||||
use Beike\Models\Product;
|
||||
use Beike\Models\ProductDescription;
|
||||
use Beike\Models\ProductSku;
|
||||
use Beike\Admin\Services\ProductService;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -94,4 +92,11 @@ class ProductController extends Controller
|
|||
|
||||
return redirect($this->getRedirect())->with('success', 'product created');
|
||||
}
|
||||
|
||||
public function name(int $id)
|
||||
{
|
||||
$name = ProductRepo::getName($id);
|
||||
|
||||
return json_success('获取成功', $name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,4 +36,14 @@ class CategoryRepo
|
|||
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getName($id)
|
||||
{
|
||||
$category = Category::query()->find($id);
|
||||
|
||||
if ($category) {
|
||||
return $category->description->name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ Route::prefix($adminName)
|
|||
Route::Resource('customer_groups', Controllers\CustomerGroupController::class);
|
||||
|
||||
Route::put('products/restore', [Controllers\ProductController::class, 'restore']);
|
||||
Route::get('categories/{id}/name', [Controllers\CategoryController::class, 'name'])->name('categories.name');
|
||||
Route::get('products/{id}/name', [Controllers\ProductController::class, 'name'])->name('products.name');
|
||||
Route::resource('products', Controllers\ProductController::class);
|
||||
Route::resource('currencies', Controllers\CurrencyController::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -109,4 +109,19 @@ class ProductRepo
|
|||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品名称
|
||||
* @param $id
|
||||
* @return \Illuminate\Database\Eloquent\HigherOrderBuilderProxy|mixed|string
|
||||
*/
|
||||
public static function getName($id)
|
||||
{
|
||||
$product = Product::query()->find($id);
|
||||
|
||||
if ($product) {
|
||||
return $product->description->name;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue