amk
1 year ago

Laravel Datatable

Posted 1 year ago by amk

can't show data in view when come from controller..... I have been test my controller.it work well... this is from blade..

@extends('backend.layouts.master')
@section('title','Teacher')
@section('style')
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet">
@endsection
@section('script')
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  $('#users-table').DataTable({
    processing: true,
    serverSide: true,
    ajax: '{!!route('teachers.data')!!}',
    columns: [
        {data: 'id', name: 'id'},
        {data: 'name', name: 'name'},
        {data: 'phone', name: 'phone'},
        {data: 'created_at', name: 'created_at'},
        {data: 'updated_at', name: 'updated_at'}
    ]
  });
});
</script>
@endsection
@section('content')
<section class="content">
        <a href="{{route('teacher.create')}}" class="btn btn-info">Add Teacher</a>
        <div class="row">
            <div class="col-md-12">
                <table class="table table-bordered table-hover table-striped" id="users-table">
                    <thead>
                        <tr>
                            <th>id</th>
                            <th>name</th>
                            <th>phone</th>
                            <th>created_at</th>
                            <th>updated_at</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
  <br>
</section>
@endsection

and controller

public function data(){
      $teacher = Teacher::select(['id', 'name', 'phone','created_at', 'updated_at']);
      return Datatables::of($teacher)
      ->make(true);
    }

Please sign in or create an account to participate in this conversation.