πŸš€ DevOps Certified Professional
πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 | 🀝 +1 (469) 756-6329 πŸ” Contact@DevOpsSchool.com

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

DevOps

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started 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