Laravel deosnt的Yajra Datatables包与laravel 5.2一起正常工作

时间:2016-03-26 14:48:07

标签: datatable laravel-5.2 datatables-1.10

我安装了yajra / laravel-datatables-oracle" ~6.0"用于支持laravel 5.2中的服务器端数据表的包,其中MySql作为数据库。 我试图显示用户的数据表:

//routes.php
Route::group(['middleware' => ['web'], 'prefix' => 'user'], function () {
    Route::get('/index', 'UserController@index')->name('user.index');
});

这是我的控制器:

//UserController.php
public function index()
{
    return view('user.index');
}

public function indexData()
{
    $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get();
    return Datatables::of($users)->make();
}

观点:

// user\index.blade.php
@extends('layouts.base')

@section('additional_styles')
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css">
@endsection

@section('additional_scripts')
    <!-- DataTables -->
    <script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
    <script>
        $('#users-table').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": '{!! route('user.index') !!}',
            "columns": [
                {data: 'id', name: 'id'},
                {data: 'name', name: 'name'},
                {data: 'email', name: 'email'},
                {data: 'created_at', name: 'created_at'},
                {data: 'updated_at', name: 'updated_at'}
            ]
        });
    </script>
@endsection


@section('main-content')
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <table class="table table-bordered" id="users-table">
                            <thead>
                            <tr>
                                <th>Id</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Created At</th>
                                <th>Updated At</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

但数据表无法正常工作。在处理以呈现数据之后,它向我显示响应具有无效JSON格式的警报并且说要查看datatables.net/tn/1。我试图在chrome的开发工具中查看响应,但我不能!

关于这个问题的任何想法?

0 个答案:

没有答案