app/Http/Controllers/UsersController.php
<?php
namespace App\Http\Controllers;
use App\Datatables\UserDatatableCruds;
use App\Datatables\ProductsDatatableCruds;
use App\Models\User;
use App\Models\Product;
use Exist404\DatatableCruds\Facades\DatatableCruds;
use Illuminate\Http\Request;
class UsersController extends Controller
{
public function index(
UserDatatableCruds $usersDatatable,
ProductsDatatableCruds $productsDatatable
) {
if ($usersDatatable->isXhr()) {
return $usersDatatable->getResults();
} elseif ($productsDatatable->isXhr()) {
return $productsDatatable->getResults();
}
return view('app', ['users' => $usersDatatable, 'products' => $productsDatatable]);
}
}
resources/views/app.blade.php
notice! by default you don't need to add datatable script or #datatablecruds div in your layout blade these tags will be injected by the package middleware, but if you put them, the middleware will not inject them
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover, shrink-to-fit=no">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="theme-color" content="/docs/2.x/multiple-datatables#100DD1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
@datatableScript
</head>
<body>
<div id="datatablecruds">
{{ $users->table() }}
{{ $products->table() }}
</div>
</body>
</html>