How to get data from database and display in homepage in laravel

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

step1

create a controller usning following comand

php artisan make:controller StudentController

use the code mentioned below in controller :-

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;Use App\User;

class StudentController extends Controller{
      public function index()    {  
      $students = User::all();
      return view('home',compact('students'));  
}}

Step 2

Using foreach loop just display the data in tabular forn by creating a table in home page using mentioned below code in home.blade.php

Step 3

The last and and final step is to set route to call studentController to view data. Just add following code in route/web.php

Route::get('view-records','StudentController@index')->name('view-records'); 

complted :

If we want to view our data from database then just we use mentioned url in our brouser :-http://127.0.0.1:8000/view_records