title: i want to view only last data i have entered in my database but it showing all data from database in laravel-8
body: <p>i am doing a project where in my index.blade.php I want to show only the last data I have entered but the route I write it shows all data from database. how can I show only the last data I have entered. Thanks in advance.
  Could you see on my code and help me.
  Here Is the code from my index.blde.php</p>
  <pre><code>@extends('products.layout')
  
  @section('content')
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;pull-right&quot;&gt;
              &lt;!-- Authentication --&gt;
                 &lt;form method=&quot;POST&quot; action=&quot;{{ route('logout') }}&quot;&gt;
                     @csrf
  
                     &lt;x-jet-dropdown-link href=&quot;{{ route('logout') }}&quot;
                             onclick=&quot;event.preventDefault();
                                     this.closest('form').submit();&quot;&gt;
                         {{ __('Log Out') }}
                     &lt;/x-jet-dropdown-link&gt;
                 &lt;/form&gt;
             &lt;/div&gt;
          {{--  --}}
          &lt;div class=&quot;col-lg-12 margin-tb&quot;&gt;
              &lt;div class=&quot;pull-left&quot;&gt;
                  &lt;h2&gt;Click Button&lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class=&quot;pull-right&quot;&gt;
                  &lt;a class=&quot;btn btn-success&quot; href=&quot;{{ route('products.create') }}&quot;&gt; For New Data&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      @if ($message = Session::get('success'))
          &lt;div class=&quot;alert alert-success&quot;&gt;
              &lt;p&gt;{{ $message }}&lt;/p&gt;
          &lt;/div&gt;
      @endif
  
      &lt;table class=&quot;table table-bordered&quot;&gt;
          &lt;tr&gt;
              &lt;th&gt;No&lt;/th&gt;
              &lt;th&gt;App Name&lt;/th&gt;
              &lt;th&gt;App Logo&lt;/th&gt;
              &lt;th&gt;Splash Image&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Color&lt;/th&gt;
              &lt;th width=&quot;280px&quot;&gt;Action&lt;/th&gt;
          &lt;/tr&gt;
          @foreach ($products as $product)
          &lt;tr&gt;
              &lt;td&gt;{{ ++$i }}&lt;/td&gt;
              &lt;td&gt;{{ $product-&gt;name }}&lt;/td&gt;
              &lt;td&gt;&lt;img src=&quot;/logo/{{ $product-&gt;logo }}&quot; width=&quot;100px&quot;&gt;&lt;/td&gt;
              &lt;td&gt;&lt;img src=&quot;/image/{{ $product-&gt;image }}&quot; width=&quot;100px&quot;&gt;&lt;/td&gt;
  
              &lt;td&gt;{{ $product-&gt;detail }}&lt;/td&gt;
              &lt;td&gt;{{ $product-&gt;color }}&lt;/td&gt;
              &lt;td&gt;
                  &lt;form action=&quot;{{ route('products.destroy',$product-&gt;id)}}&quot; method=&quot;POST&quot;&gt;
  
                      &lt;a class=&quot;btn btn-info&quot; href=&quot;{{ route('products.show',$product-&gt;id) }}&quot;&gt;Show&lt;/a&gt;
  
                      &lt;a class=&quot;btn btn-primary&quot; href=&quot;{{ route('products.edit',$product-&gt;id) }}&quot;&gt;Edit&lt;/a&gt;
  
                      &lt;a class=&quot;btn btn-info&quot; href=&quot;products_link&quot;&gt;Get Json&lt;/a&gt;
  
                      @csrf
                      @method('DELETE')
  
                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-danger&quot;&gt;Delete&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          @endforeach
      &lt;/table&gt;
  
      {!! $products-&gt;links() !!}
  
  @endsection
  
  </code></pre>
  <p>This is ProductController.php</p>
  <pre><code> &lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Models\Product;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\DB;
  use App\Http\Requests\Admin\StoreTagsRequest;
  
  class ProductController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          //$tags = Product::all();
          //return view('products.index', compact('tags'));
  
          $products = Product::latest()-&gt;paginate(5);
  
          return view('products.index',compact('products'))
  
              -&gt;with('i', (request()-&gt;input('page', 1) - 1) * 5);
      }
  
      /**
       * 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)
      {
          //$tag = Product::create($request-&gt;all());
  
          //return redirect()-&gt;route('admin.tags.index');
          $request-&gt;validate([
              'name' =&gt; 'required',
              'detail' =&gt; 'required',
              'color' =&gt; 'required',
              'image' =&gt; 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
              'logo' =&gt; 'required|mimes:jpeg,png,jpg,gif,svg|max:512',
          ]);
  
          $input = $request-&gt;all();
  
          if ($image = $request-&gt;file('image')) {
              $destinationPath = 'image/';
              $profileImage = date('YmdHis') . &quot;.&quot; . $image-&gt;getClientOriginalExtension();
              $image-&gt;move($destinationPath, $profileImage);
              $input['image'] = &quot;$profileImage&quot;;
          }
  
          if ($logo = $request-&gt;file('logo')) {
              $destinationPath = 'logo/';
              $profileLogo = date('YmdHis') . &quot;.&quot; . $logo-&gt;getClientOriginalExtension();
              $logo-&gt;move($destinationPath, $profileLogo);
              $input['logo'] = &quot;$profileLogo&quot;;
          }
  
          Product::create($input);
  
          return redirect()-&gt;route('products.index')
                          -&gt;with('success','Product created successfully.');
      }
  
      /**
       * Display the specified resource.
       *
       * @param  \App\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\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\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, Product $product)
      {
          $request-&gt;validate([
              'name' =&gt; 'required',
              'detail' =&gt; 'required',
              'color' =&gt; 'required'
          ]);
  
          $input = $request-&gt;all();
  
          if ($image = $request-&gt;file('image')) {
              $destinationPath = 'image/';
              $profileImage = date('YmdHis') . &quot;.&quot; . $image-&gt;getClientOriginalExtension();
              $image-&gt;move($destinationPath, $profileImage);
              $input['image'] = &quot;$profileImage&quot;;
          }else{
              unset($input['image']);
          }
  
          if ($logo = $request-&gt;file('logo')) {
              $destinationPath = 'logo/';
              $profileLogo = date('YmdHis') . &quot;.&quot; . $logo-&gt;getClientOriginalExtension();
              $logo-&gt;move($destinationPath, $profileLogo);
              $input['logo'] = &quot;$profileLogo&quot;;
          }else{
              unset($input['logo']);
          }
  
          $product-&gt;update($input);
  
          return redirect()-&gt;route('products.index')
                          -&gt;with('success','Product updated successfully');
      }
  
      /**
       * Remove the specified resource from storage.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function destroy(Product $product)
      {
          $product-&gt;delete();
  
          return redirect()-&gt;route('products.index')
                          -&gt;with('success','Product deleted successfully');
      }
  
      function indextwo(){
          //return DB::select(&quot;select * from  products&quot;);
         //DB::table('products')-&gt;orderBy('id','desc')-&gt;first();
         return Product::orderBy('id', 'DESC')-&gt;first();
      }
      
  }
  
  </code></pre>