Retrieve data from database using Laravel

Retrieve data from database using Laravel

     

Retrieve data from database using Laravel



Step 1: Install Laravel 5.7 Project

In the first step, we will install Laravel 7 application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 1: Database connection

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=management_system
DB_USERNAME=root
DB_PASSWORD=123456

Step 1: route

// ------------------------ form ------------------------ // Route::get('viewStudent', 'StudentController@viewStudent')->name('viewStudent'); Route::post('/insertStudent', 'StudentController@insertStudent'); Route::get('reportStudent', 'StudentController@reportStudent')->name('reportStudent'); 

Step : StudentController.php/useUpdate

     public function reportStudent()
    {
        $user = Auth::user();
        $reportStudent = DB::table('students')
            ->get();
        return view('report.report_student',compact('user',$user,'reportStudent'));
    }    public function reportStudent()
    {
        $user = Auth::user();
        $reportStudent = DB::table('students')
            ->get();
        return view('report.report_student',compact('user',$user,'reportStudent'));
    }

Step 2: password/user

View/report/student_report.blade.php

@extends('layouts.master')
@section('menu')
@include('sidebar.report_student')

<div class="pcoded-content">
    <div class="pcoded-inner-content">
      <div class="main-body">
        <div class="page-wrapper">
            <div class="page-header">
                <div class="row align-items-end">
                    <div class="col-lg-8">
                        <div class="page-header-title">
                            <div class="d-inline">
                                <h4>Table Report</h4>
                                <span>Report display all</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4">
                        <div class="page-header-breadcrumb">
                            <ul class="breadcrumb-title">
                                <li class="breadcrumb-item">
                                    <a href="index-1.htm"> <i class="feather icon-home"></i> </a>
                                </li>
                                <li class="breadcrumb-item"><a href="#!">User Table</a>
                                </li>
                                <li class="breadcrumb-item"><a href="#!">Back home</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>


            <div class="page-body">
                <div class="row">
                    <div class="col-sm-12">
                        <!-- Zero config.table start -->
                        <div class="card">
                            <div class="card-header">
                                <h5>Student Report</h5>
                                <span>report total</span>
                            </div>
                            <div class="card-block">
                                <div class="table-responsive dt-responsive">
                                    <table id="dom-jqry" class="table table-sm table-striped table-bordered nowrap">
                                        <thead>
                                            <tr>
                                                <th>ID STUDENT</th>
                                                <th>NAME</th>
                                                <th>SEX</th>
                                                <th>AGE</th>
                                                <th>EMAIL</th>
                                                <th>PHONE</th>
                                                <th>ACTOIN</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($reportStudent as $item)
                                            <tr role="row" class="odd">
                                            <td class="idStudent">{{$item->id_student}}</td>
                                                <td class="name">{{$item->name}}</td>
                                                <td class="sex">{{$item->sex}}</td>
                                                <td class="age">{{$item->age}}</td>
                                                <td class="email">{{$item->email}}</td>
                                                <td class="phone">{{$item->phone_number}}</td>
                                                <td class="text-center">
                                                    <a class="m-r-15 text-muted studentEdits" data-toggle="modal" data-idUpdate="''" data-target="#userUpdate">
                                                        <i class="icofont icofont-ui-edit" style="color: #2196f3;"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>

                         
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // select edit user
    $(document).on('click', '.studentEdits', function()
    {
        var _this = $(this).parents('tr');
        $('#idUpdate').val(_this.find('.idUpdate').text());
        $('#e_idStudent').val(_this.find('.idStudent').text());
        $('#e_name').val(_this.find('.name').text());
        $('#e_sex').val(_this.find('.sex').text());
        $('#e_age').val(_this.find('.age').text());
        $('#e_email').val(_this.find('.email').text());
        $('#e_phone').val(_this.find('.phone').text());
    });
</script>

@endsection



Reactions

Post a Comment

0 Comments

close