Я не мог найти такие вопросы, как этот.Все остальные вопросы не используют таблицы данных Bootstrap, как я, - они создали свою собственную таблицу.
Приложение Laravel 5.8 в настоящее время возвращает список пользователей в доступной для поиска базе данных.Проблема в том, что он возвращает ВСЕХ пользователей одновременно, поэтому страница загружается очень медленно, так как в приложении много пользователей.
Мой routes\web.php
:
Route::get('/admin/customers', 'Admin\CustomerController@renderPage')->name('admin.customers');
Мой app\Http\Controllers\Admin\CustomerController.php
:
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use ConsoleTVs\Charts\Facades\Charts;
use App\User;
class CustomerController extends Controller
{
public function renderPage() {
$customers = User::get();
return view('pages.admin.customers')->with([
'customers' => $customers
]);
}
}
Моя таблица в представлении resources\views\pages\admin\customers.blade.php
генерируется следующим образом (я удалил не соответствующий HTML-код):
<!-- Bootstrap -->
<link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- Datatables -->
<link rel="stylesheet" href="/css/dataTables.bootstrap.min.css">
<div class="table-responsive">
<table class="table table-condensed table-hover" id="customers-table">
<thead>
<tr>
<th>#</th>
<th>First name</th>
<th>Last Name</th>
<th>Email Address</th>
</tr>
</thead>
<tbody>
@foreach($customers as $customer)
<tr>
<td>{{ $customer->id }}</td>
<td>{{ $customer->first_name }}</td>
<td>{{ $customer->last_name }}</td>
<td>{{ $customer->email }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- Datatables -->
<script src="/js/jquery.dataTables.min.js"></script>
<script src="/js/dataTables.bootstrap.min.js"></script>
<script>
// Datatable settings
$(document).ready(function() {
$('#customers-table').DataTable({
"language": {
"lengthMenu": "Show _MENU_ entires per page",
"search": "Search:",
"decimal": ".",
"thousands": ",",
"zeroRecords": "No entries found.",
"info": "Showing entries _START_ to _END_ of total _TOTAL_",
"infoEmpty": "No entries available.",
"infoFiltered": "(filtered from _MAX_ total entries)",
"paginate": {
"first": "First",
"last": "Last",
"next": "Next",
"previous": "Previous"
}
}
});
} );
</script>
Итак, вопрос в том, чтомне нужно обновить до чего, чтобы добавить поддержку пагинации?