| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Http\Requests\Product\StoreProductRequest;
- use App\Http\Requests\Product\UpdateProductRequest;
- use App\Models\Product;
- use App\Services\ProductService;
-
- class ProductController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- return inertia('Products/Index', [
- 'initialSearch' => request('search'),
- 'products' => Product::filter(request()->only('search'))
- ->latest()
- ->paginate(10)
- ->withQueryString()
- ->through(fn($product) => [
- 'id' => $product->id,
- 'number' => $product->number,
- 'name' => $product->name,
- 'unit' => $product->unit,
- 'isUsed' => ProductService::isUsed($product)
- ])
- ]);
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- return inertia('Products/Create', [
- 'number' => 'PDK' . now()->format('YmdHis')
- ]);
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(StoreProductRequest $request)
- {
- Product::create($request->validated());
-
- return back()->with('success', __('messages.success.store.product'));
- }
-
- /**
- * Display the specified resource.
- *
- * @param Product $product
- * @return \Illuminate\Http\Response
- */
- public function show(Product $product)
- {
- //
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param Product $product
- * @return \Illuminate\Http\Response
- */
- public function edit(Product $product)
- {
- return inertia('Products/Edit', compact('product'));
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param Product $product
- * @return \Illuminate\Http\Response
- */
- public function update(UpdateProductRequest $request, Product $product)
- {
- $product->update($request->validated());
-
- return back()->with('success', __('messages.success.update.product'));
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param Product $product
- * @return \Illuminate\Http\Response
- */
- public function destroy(Product $product)
- {
- $product->delete();
-
- return back()->with('success', __('messages.success.destroy.product'));
- }
- }
|