Crud Application Part # 2 How to Fetch Records in LARAVEL

 Controller Code:



    public function display()
    {

            $data = DB::select('select * from employees');
           //dd($data);


        return view('display',compact('data'));
    }


Display Code:


<!doctype html>
<html lang="en">
  <head>
    <title>Title</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS v5.0.2 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css&quot;  integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

  </head>
  <body>


    <ul class="nav nav-tabs">
        <li class="nav-item">
          <a class="nav-link active" href="{{url('/employee')}}">Employee Form</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Disabled</a>
        </li>
      </ul>

      <br>

    <br>
<table class="table table-bordered">

    <thead>
            <tr>

                <th> ID </th>
                <th> NAME </th>
                <th> AGE </th>
                <th> SALARY </th>

            </tr>


    </thead>


    <tbody>

@foreach ($data as  $item)


    <tr>
     <th scope="row"> {{$item->id}} </th>
        <td>{{$item->name}}  </td>
        <td>{{$item->age}}  </td>
        <td>{{$item->salary}}  </td>

        <td> <a href="" class="btn btn-info"> UPDATE </a> | <a href="" class="btn btn-danger"> DELETE </a>  </td>

    </tr>





@endforeach

</tr>

    </tbody>
</table>
    <!-- Bootstrap JavaScript Libraries -->
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js&quot; integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js&quot; integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
  </body>
</html>


Route Code:



Route::get('/display' , [EmployeeController::class,'display']);

Comments