PHP code example of distilleries / datatable-builder
1. Go to this page and download the library: Download distilleries/datatable-builder 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/ */
distilleries / datatable-builder example snippets
namespace App\Http\Controllers;
use App\Datatables\UserDatatable;
class DatatableController extends Controller {
use \Distilleries\DatatableBuilder\States\DatatableStateTrait;
/*
|--------------------------------------------------------------------------
| Welcome Controller
|--------------------------------------------------------------------------
|
| This controller renders the "marketing page" for the application and
| is configured to only allow guests. Like most of the other sample
| controllers, you are free to modify or remove it as you desire.
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(\App\User $model, UserDatatable $datatable)
{
$this->model = $model;
$this->datatable = $datatable;
}
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function getIndex()
{
return view('welcome',[
'datatable'=>$this->getIndexDatatable()
]);
}
}
sh
php artisan datatable:make Datatables/PostDatatable
php
namespace App\Datatables;
use Distilleries\DatatableBuilder\EloquentDatatable;
class PostDatatable extends EloquentDatatable
{
public function build()
{
// Add fields here...
$this->addDefaultAction();
}
}
sh
php artisan datatable:make Datatables/SongDatatable --fields="name, lyrics"
php
namespace App\Datatables;
use Distilleries\DatatableBuilder\EloquentDatatable;
class SongDatatable extends EloquentDatatable
{
public function build()
{
$this
->add('name',null,_('Name'))
->add('lyrics',null,_('Lyrics'));
$this->addDefaultAction();
}
}