PHP code example of syscage / laravel-datatable

1. Go to this page and download the library: Download syscage/laravel-datatable 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/ */

    

syscage / laravel-datatable example snippets


use Syscage\Datatable\Facades\Syscage;

return Syscage::datatable(User::class)
    ->search(['name', 'email', 'roles.name'])
    ->sortable(['id', 'name', 'created_at'])
    ->filter(['status', 'country'])
    ->where('is_active', true)
    ->latest();

use Syscage\Datatable\Facades\Syscage;

// From a model class name
return Syscage::datatable(User::class);

// From an already-built Eloquent query
return Syscage::datatable(User::query()->where('status', 1));

// From a relation
return Syscage::datatable($company->users());

// From the query builder
return Syscage::datatable(DB::table('users'));

// From a collection
return Syscage::datatable(User::all());

// From a lazy collection
return Syscage::datatable(User::cursor());

// From a plain array
return Syscage::datatable($rows);

class UserController
{
    public function index()
    {
        return Syscage::datatable(User::class)
            ->search(['name', 'email'])
            ->sortable(['id', 'name', 'email', 'created_at'])
            ->filter(['status', 'country'])
            ->resource(UserResource::class);
    }
}
bash
php artisan vendor:publish --tag=datatable-config