Hallo,
ich hangel mich gerade entlang eines Beispiels mit dem DataTables in Laravel.
Irgendwie bekomme ich keine richtige JSON zurück.
Controller:
Index.blade.php
Er meldet mir:
Ich habe den Fehler gegoogelt, aber ich komme nicht drauf.
Mit tinker bekomme ich das hier als Response:
ich hangel mich gerade entlang eines Beispiels mit dem DataTables in Laravel.
Irgendwie bekomme ich keine richtige JSON zurück.
Controller:
PHP-Code:
namespace App\Http\Controllers;
use App\Http\Requests;
use App\User;
use Yajra\Datatables\Datatables;
class DatatablesController extends Controller
{
/**
* Displays datatables front end view
*
* @return \Illuminate\View\View
*/
public function getIndex()
{
return view('datatables.index');
}
/**
* Process datatables ajax request.
*
* @return \Illuminate\Http\JsonResponse
*/
public function anyData()
{
$users = User::select(['id', 'name', 'email', 'created_at', 'updated_at']);
return Datatables::of($users)->make();
}
}
PHP-Code:
extends('layouts.master')
@section('content')
<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>
@stop
@push('scripts')
<script>
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('datatables.data') !!}',
columns: [
{data: 'id'},
{data: 'name'},
{data: 'email'},
{data: 'created_at'},
{data: 'updated_at'}
]
});
</script>
@endpush
PHP-Code:
DataTables warning: table id=users-table - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Ich habe den Fehler gegoogelt, aber ich komme nicht drauf.
Mit tinker bekomme ich das hier als Response:
PHP-Code:
>>> return Datatables::of(User::select(['id', 'name', 'email', 'created_at', 'updated_at']))->make()
=> Illuminate\Http\JsonResponse {#4067
+headers: Symfony\Component\HttpFoundation\ResponseHeaderBag {#4065},
+original: [
"draw" => 0,
"recordsTotal" => 51,
"recordsFiltered" => 51,
"data" => [
[
"id" => "1",
"name" => "Meier",
"email" => "XXX@XXX.net",
"created_at" => "2020-05-23T20:10:25.000000Z",
"updated_at" => "2020-05-23T20:10:25.000000Z",
],
[
"id" => "2",
"name" => "Jaren Batz",
"email" => "maxime.kulas@example.org",
"created_at" => "2020-05-25T17:27:06.000000Z",
"updated_at" => "2020-05-25T17:27:06.000000Z",
],
[
"id" => "3",
"name" => "Dr. Tyson Gibson",
"email" => "pete.champlin@example.org",
"created_at" => "2020-05-25T17:27:06.000000Z",
"updated_at" => "2020-05-25T17:27:06.000000Z",
],
[
"id" => "4",
"name" => "Prof. Megane Herzog III",
"email" => "garnett68@example.org",
"created_at" => "2020-05-25T17:27:06.000000Z",
"updated_at" => "2020-05-25T17:27:06.000000Z",
],
],
"queries" => [
[
"query" => "select count(*) as aggregate from (select '1' as `row_count` from `users`) count_row_table",
"bindings" => [],
"time" => "168.45",
],
[
"query" => "select `id`, `name`, `email`, `created_at`, `updated_at` from `users`",
"bindings" => [],
"time" => "2.18",
],
],
"input" => [],
],
+exception: null,
}
Kommentar