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()
{
$users = UserDatatableCruds::init()->renderData();
$products = ProductsDatatableCruds::init()->renderData();
return view("app", compact("users", "products"));
}
public function getUsers()
{
return dataTableOf(User::withCount('posts'));
}
public function getProducts()
{
return dataTableOf(Product::where('quantity', '>', 0));
}
}
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/1.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">
@datatable($users)
@datatable($products)
</div>
</body>
</html>