# 4.3 Show Product (ok)

<figure><img src="https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FWU2VMbXqZnMlGDGlkmf4%2Fimage.png?alt=media&#x26;token=6d639655-42d8-4787-a75d-7ae1c78123e6" alt=""><figcaption></figcaption></figure>

C:\xampp82\htdocs\phongkhamnet\app\Http\Controllers\ProductController.php

```php
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
class ProductController extends Controller
{
  /**
   * Display a listing of the resource.
   */
  public function index()
  {
    $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(Request $request)
  {
    $input = $request->all();
    if ($image = $request->file('image')) {
      $destinationPath = 'image/';
      $productImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
      $image->move($destinationPath, $productImage);
      $input['image'] = "$productImage";
    }
    Product::create($input);
    return redirect()->route('products.index');
  }
  /**
   * 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)
  {
    //
  }
  /**
   * Update the specified resource in storage.
   */
  public function update(Request $request, Product $product)
  {
    //
  }
  /**
   * Remove the specified resource from storage.
   */
  public function destroy(Product $product)
  {
    //
  }
}

```

C:\xampp82\htdocs\phongkhamnet\resources\views\products\show.blade.php

```blade
@extends('layouts.app')
@section('content')
<div class="row">
  <div class="col-lg-12 margin-tb">
    <div class="pull-left">
      <h2> Show Product</h2>
    </div>
    <div class="pull-right">
      <a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group">
      <strong>Image:</strong>
      <img src="/image/{{ $product->image }}" width="500px">
    </div>
  </div>
  <div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group">
      <strong>Name:</strong>
      {{ $product->name }}
    </div>
  </div>
  <div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group">
      <strong>Price:</strong>
      {{ $product->price }}
    </div>
  </div>
  <div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group">
      <strong>Details:</strong>
      {{ $product->detail }}
    </div>
  </div>
</div>
<p class="text-center text-primary"><small>by Noor E Alam</small></p>
@endsection

```
