1. Go to this page and download the library: Download dykhuizen/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/ */
dykhuizen / laravel-datatable example snippets
use Dykhuizen\Datatable;
use Illuminate\Database\Eloquent\Model;
use Dykhuizen\Datatable\Datatable;
class User extends Model
{
use Datatable;
}
public function addressSortable($query, $direction)
{
return $query->join('profiles', 'users.id', '=', 'profiles.user_id')->orderBy('address', $direction)->select('users.*');
}
public function addressSearchable($query, $search)
{
return $query->whereHas('profile', function($query) use ($search)
{
return $query->where('address', '=', $search);
});
}
public function addressFilterable($query, $filters)
{
return $query->where(function($query) use($filters) {
foreach($filters as $filter) {
switch($filters) {
case 'local':
$query->orWhere(...);
break;
case 'foreign':
$query->orWhere(...);
break;
default:
$query->orWhere(...);
break;
}
}
return $query;
});
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.