我想在我的laravel 5.6应用程序中使用yajra数据表,我已经使用此安装yajra软件包(编写者需要yajra / laravel-datatables-oracle),并在使用php artisan serve运行该应用程序时将js包含在布局文件中它会显示此错误(DataTables警告:table id = datatableclass-无效的JSON响应。)任何人都可以提前解决此问题。
config / app
'providers' => [
....
Yajra\Datatables\DatatablesServiceProvider::class,
],
'aliases' => [
....
'Datatables' => 'Yajra\Datatables\Facades\Datatables',
]
这是ajax调用
$(document).ready(function() {
$('#datatableclass').DataTable({
processing: true,
serverSide: true,
ajax: '{{ route('class.getclasses') }}',
columns: [
{data: 'id', name: 'id'},
{data: 'class_name', name: 'class_name'},
]
});
});
这是我的路线
Route::resource('/class','ClassController');
Route::get('/class/get-classes', 'ClassController@getClass')->name('class.getclasses');
这是我的控制器
use Illuminate\Http\Request;
use App\Http\Requests\SchoolClassRequest;
use App\SchoolClass;
use Datatables;
public function index()
{
return view('school_admin.entry.class');
}
public function getClass()
{
$school = auth()->user()->school()->first();
$classes = SchoolClass::where('school_id', $school->id)->get();
return DataTables::of($classes)->make(true);
}
这是我的视图表
<table class="table" id="datatableclass">
<thead>
<tr>
<th data-field="ID">Id</th>
<th data-field="Class" data-sortable="true">Class Name</th>
</tr>
</thead>
</table>