Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Models\Product;
- use Illuminate\Http\Request;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Response;
- use Illuminate\View\View;
- use App\Http\Requests\ProductStoreRequest;
- use App\Http\Requests\ProductUpdateRequest;
- class ProductController extends Controller
- {
- /**
- * Display a listing of the resource.
- */
- public function index()
- {
- //
- //$products = Product::all();
- //return view('products.index', compact('products'));
- $products = Product::latest()->paginate(5);
- return view('products.index', compact('products'))
- ->with('i', (request()->input('page', 1) - 1) * 5);
- }
- /**
- * Show the form for creating a new resource.
- */
- public function create()
- {
- //
- return view('products.create');
- }
- /**
- * Store a newly created resource in storage.
- */
- public function store(ProductStoreRequest $request)
- {
- //
- Product::create($request->validated());
- return redirect()->route('products.index')
- ->with('success', 'Product created successfully.');
- }
- /**
- * Display the specified resource.
- */
- public function show(Product $product)
- {
- //
- return view('products.show',compact('product'));
- }
- /**
- * Show the form for editing the specified resource.
- */
- public function edit(Product $product)
- {
- //
- return view('products.edit',compact('product'));
- }
- /**
- * Update the specified resource in storage.
- */
- public function update(ProductUpdateRequest $request, Product $product)
- {
- //
- $product->update($request->validated());
- return redirect()->route('products.index')
- ->with('success','Product updated successfully');
- }
- /**
- * Remove the specified resource from storage.
- */
- public function destroy(Product $product)
- {
- //
- $product->delete();
- return redirect()->route('products.index')
- ->with('success','Product deleted successfully');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement