Вот мой LeadController, который обрабатывает внутреннюю логику выборки. записи с разбивкой на страницы:
LeadController.php
Код: Выделить всё
public function index()
{
$users = User::all();
// Check if a user is authenticated
if (Auth::check()) {
// Get the currently authenticated user
$user = Auth::user();
// Check if the user has the role of 'superadmin'
if ($user->role === 'superadmin') {
// Show all leads for superadmin, paginated
$leads = Lead::latest()->paginate(10); // Change 10 to the number of leads per page
} else {
// Filter leads assigned to the current user, paginated
$leads = Lead::where('lead_user', $user->id)->latest()->paginate(10); // Change 10 as needed
}
} else {
// If no user is authenticated, handle as needed
$leads = Lead::latest()->paginate(10); // Change 10 as needed
}
return view('leads.index', compact('leads', 'users'));
}
Код: Выделить всё
// var e;
c1 = $('#style-1').DataTable({
headerCallback:function(e, a, t, n, s) {
e.getElementsByTagName("th")[0].innerHTML=`
`
},
columnDefs:[ {
targets:0, width:"30px", className:"", orderable:!1, render:function(e, a, t, n) {
return `
`
}
}],
"dom": "" +
"" +
"",
"oLanguage": {
"oPaginate": { "sPrevious": '
', "sNext": '' },
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"lengthMenu": [5, 10, 20, 50],
"pageLength": 10
});
multiCheck(c1);
Использование отдельной логики поиска путем добавления дополнительной конечной точки внутреннего поиска. Однако этот подход неуклюж и плохо интегрируется со встроенным поиском DataTables.
Подробнее здесь: https://stackoverflow.com/questions/793 ... on-laravel