1. Go to this page and download the library: Download josegus/laravel-dash library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\DataTables;
use App\Users;
use Dash\DataTables\Datatable;
class UsersTable extends Datatable
{
public function query()
{
return Users::query();
}
}
namespace App\Http\Controllers\Api;
use App\DataTables\UsersTable;
class UsersController
{
public function index()
{
return UsersTable::generate();
}
}
public function query()
{
return Users::query()
->where('status', 'active')
->whereHas('courses', function ($courses) {
$courses->where('status', 'open');
})
->select(['id', 'name', 'email'])
->with(['posts']);
}