Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To exhibit information gathered from a database using Laravel, here are the steps you can follow:

  1. Create a Controller: In Laravel, the controller is responsible for communicating with the model and the view. Create a controller by running the following command in your terminal:
php artisan make:controller DataController
  1. Define a function in the controller to retrieve data from the database:
public function index(){
    $data = DB::table('table_name')->get();
    return view('data', compact('data'));
}
  1. Create a View: A view is used to display the retrieved data. Create a view 'data.blade.php':
@extends('layouts.app')

@section('content')
<div class="container">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            @foreach($data as $row)
            <tr>
                <td>{{ $row->id }}</td>
                <td>{{ $row->name }}</td>
                <td>{{ $row->email }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>
@endsection
  1. Route the View: Route the view to the DataController by editing the routes/web.php file:
Route::get('/data', 'DataController@index');
  1. Access the View: Access the view by opening the URL http://localhost:8000/data in your browser. The information gathered from the database will be displayed in the table.

Note: This is just a basic example to exhibit information gathered from a database using Laravel. You can modify it as per your requirements. Additionally, ensure that the database configuration in the .env file is correct before getting started.