所以,这是我的控制器:
use Yajra\DataTables\Facades\DataTables;
class CategoriasController extends Controller
{
public function index()
{
return Datatables::collection(Categoria::all())->make(true);
}
[...]
}
这是我的路线:
Route::group(['middleware' => 'auth'], function () {
Route::group(['middleware' => 'admin'], function () {
Route::prefix('admin')->namespace('Admin')->group(function () {
Route::prefix('categorias')->group(function(){
Route::get('/', 'CategoriasController@index')->name('curso.index');
[...]
});
});
});
});
这是我的刀片:
[...]
<div class="container">
<table class="table border" id="myTable">
<thead>
<tr>
<th>id</th>
<th>Nome</th>
<th>Criado</th>
<th>Modificado</th>
</tr>
</thead>
</table>
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready( function () {
$('#myTable').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('categoria.index') !!}',
columns: [
{ data: 'id', name:'id'},
{ data: 'nome', name:'nome'},
{ data: 'created_at', name:'created_at'},
{ data: 'updated_at', name:'updated_at'},
]
});
} );
</script>
[...]
我得到了这个作为回报:
我正在使用 Laravel5.8.19
作曲家.json
[...]
"require":{
"yajra/laravel-datatables": "^1.5",
"yajra/laravel-datatables-oracle": "~9.0"
}
那么为什么不是表格渲染呢?是我做错了什么吗?我跑了互联网,我没有找到解决方案,希望你能帮助我