# \[COMMON] Lấy tham số đường dẫn http://localhost/test/products?page=3 (ok)

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FriQateAL0wbUxXVoivxB%2FScreenshot_1.png?alt=media\&token=5b048fbd-b1d2-4a9a-8560-f15a8456bd36)

Mục đánh số thứ tự cho sản phẩm&#x20;

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FHeeMPhFNlGAZnSk2f6TV%2FScreenshot_2.png?alt=media\&token=27d4c9c1-8b92-45f0-b3ff-681b25acf80a)

C:\xampp\htdocs\test\app\Http\Controllers\ProductController.php

```
C:\xampp\htdocs\test\app\Http\Controllers\ProductController.php
```

```
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
class ProductController extends Controller {
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
  public function index() {
    $products = Product::latest()->paginate(2);
    echo '<pre>';
        var_export(request()->input('page', 1));
    echo '</pre>';
    return view('products.index', compact('products'))->with('i', (request()->input('page', 1) - 1) * 2);
  }
  /**
   * Show the form for creating a new resource.
   *
   * @return \Illuminate\Http\Response
   */
  public function create() {
    return view('products.create');
  }
  /**
   * Store a newly created resource in storage.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return \Illuminate\Http\Response
   */
  public function store(Request $request) {
    $request->validate([
      'name'   => 'required',
      'detail' => 'required',
    ]);
    Product::create($request->all());
    return redirect()->route('products.index')->with('success', 'Product created successfully.');
  }
  /**
   * Display the specified resource.
   *
   * @param  \App\Models\Product  $product
   * @return \Illuminate\Http\Response
   */
  public function show(Product $product) {
    return view('products.show', compact('product'));
  }
  /**
   * Show the form for editing the specified resource.
   *
   * @param  \App\Models\Product  $product
   * @return \Illuminate\Http\Response
   */
  public function edit(Product $product) {
    return view('products.edit', compact('product'));
  }
  /**
   * Update the specified resource in storage.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  \App\Models\Product  $product
   * @return \Illuminate\Http\Response
   */
  public function update(Request $request, Product $product) {
    $request->validate([
      'name'   => 'required',
      'detail' => 'required',
    ]);
    $product->update($request->all());
    return redirect()->route('products.index')->with('success', 'Product updated successfully');
  }
  /**
   * Remove the specified resource from storage.
   *
   * @param  \App\Models\Product  $product
   * @return \Illuminate\Http\Response
   */
  public function destroy(Product $product) {
    $product->delete();
    return redirect()->route('products.index')->with('success', 'Product deleted successfully');
  }
}
```
