Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带数据表的Laravel 5.4_Php_Laravel_Datatable - Fatal编程技术网

Php 带数据表的Laravel 5.4

Php 带数据表的Laravel 5.4,php,laravel,datatable,Php,Laravel,Datatable,我已将此软件包添加到我的软件包中,并尝试在我的应用程序中使用它 这就是观点 @section('content') <table class="table table-bordered" id="users-table"> <thead> <tr> <th>Emp No</th> <th>Birth Date&l

我已将此软件包添加到我的软件包中,并尝试在我的应用程序中使用它

这就是观点

@section('content')
    <table class="table table-bordered" id="users-table">
        <thead>
            <tr>
                <th>Emp No</th>
                 <th>Birth Date</th>
                  <th>First Name</th>
                   <th>Last Name</th>
                    <th>Gender</th>
                     <th>Hire Date</th>

            </tr>
        </thead>
    </table>
@stop

@push('scripts')

<script type="text/javascript">
$(function() {
    $('#users-table').DataTable({
        processing: true,
        serverSide: true,
        responsive: true,
        ajax: 'http://localhost:8000/tasks',
        columns: [
            { data: 'emp_no', name: 'emp_no' }
            { data: 'birth_date', name: 'birth_date' },
            { data: 'first_name', name: 'first_name' },
            { data: 'last_name', name: 'last_name' },
            { data: 'gender', name: 'gender' },
            { data: 'hire_date', name: 'hire_date' }
        ]
    });
});
</script>

@endpush
@endsection
这是控制器

public function getTasks()
    {
       return Datatables::of(Employees::query())->make(true);
       //returns json
    }
此代码加载包含数据表的视图

url在web浏览器中返回json,但数据表从未在我的视图中呈现。当我签入视图时,没有浏览器错误


有什么问题?

创建两个方法,一个显示视图,另一个处理datatables ajax请求的方法

显示我们的视图

public function viewTasks()
{
    return view('Tasks.index');
}
处理我们的datatables ajax请求

public function getTasks()
{
    return Datatables::of(Employees::query())->make(true);
}

参考链接:-

您应该在控制器中进行更改。在下面添加代码以显示数据表:

 public function task()
    {
        return view('datatables.Index');
    }
添加新路由的
web.php
文件中的更改:

Route::get( 'employee','PrototypeController@task');
还添加数据表CDN和引导

<link href="https://datatables.yajrabox.com/css/app.css" rel="stylesheet">
    <link href="https://datatables.yajrabox.com/css/datatables.bootstrap.css" rel="stylesheet">
    <link href='https://fonts.googleapis.com/css?family=Lato:400,700,300|Open+Sans:400,600,700,800' rel='stylesheet'
          type='text/css'>


我已经有了显示视图的控制器
Route::get('bulkOutbox','PrototypeController@bulkOutbox');Route::get('tasks','PrototypeController@getTasks')->name('datatable.tasks')
FirstBulkOutbox呈现此视图并运行我首先加载的bulkOutbox的url,但仍然没有显示任何内容。如果您安装了mysql示例数据库,您可以对其进行测试。这非常奇怪,没有任何jquery错误。让我们来看看。我认为,您应该更改刀片文件。因为“@endsection”在“@sctipt”之前停止。如果创建master.blade.php。。谢谢
<link href="https://datatables.yajrabox.com/css/app.css" rel="stylesheet">
    <link href="https://datatables.yajrabox.com/css/datatables.bootstrap.css" rel="stylesheet">
    <link href='https://fonts.googleapis.com/css?family=Lato:400,700,300|Open+Sans:400,600,700,800' rel='stylesheet'
          type='text/css'>