Files
moonwell-web/app/Http/Controllers/Admin/ShopController.php
T

66 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\SaveShopCategoryRequest;
use App\Http\Requests\Admin\SaveShopProductRequest;
use App\Models\ShopCategory;
use App\Models\ShopProduct;
use App\Services\ShopCatalogService;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class ShopController extends Controller
{
public function index(ShopCatalogService $catalog): View
{
return view('admin.shop.index', [
'categories' => $catalog->categories(),
'products' => $catalog->products(),
]);
}
public function storeCategory(SaveShopCategoryRequest $request, ShopCatalogService $catalog): RedirectResponse
{
$catalog->createCategory($request->validated());
return back()->with('status', 'Категория создана.');
}
public function updateCategory(ShopCategory $category, SaveShopCategoryRequest $request, ShopCatalogService $catalog): RedirectResponse
{
$catalog->updateCategory($category, $request->validated());
return back()->with('status', 'Категория обновлена.');
}
public function destroyCategory(ShopCategory $category, ShopCatalogService $catalog): RedirectResponse
{
$catalog->deleteCategory($category);
return back()->with('status', 'Категория удалена.');
}
public function storeProduct(SaveShopProductRequest $request, ShopCatalogService $catalog): RedirectResponse
{
$catalog->createProduct($request->validated());
return back()->with('status', 'Товар создан.');
}
public function updateProduct(ShopProduct $product, SaveShopProductRequest $request, ShopCatalogService $catalog): RedirectResponse
{
$catalog->updateProduct($product, $request->validated());
return back()->with('status', 'Товар обновлён.');
}
public function destroyProduct(ShopProduct $product, ShopCatalogService $catalog): RedirectResponse
{
$catalog->deleteProduct($product);
return back()->with('status', 'Товар удалён.');
}
}