1. Go to this page and download the library: Download sportdude/column-sortable 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/ */
sportdude / column-sortable example snippets
'providers' => [
App\Providers\RouteServiceProvider::class,
/*
* Third Party Service Providers...
*/
Kyslik\ColumnSortable\ColumnSortableServiceProvider::class,
],
use Kyslik\ColumnSortable\Sortable;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, Sortable;
...
public $sortable = ['id',
'name',
'email',
'created_at',
'updated_at'];
...
}
/* this is FA 5 compatible.
suffix class that is appended when ascending direction is applied */
'asc_suffix' => '-up',
/* suffix class that is appended when descending direction is applied */
'desc_suffix' => '-down',
/**
* Get the user_detail record associated with the user.
*/
public function detail()
{
return $this->hasOne(App\UserDetail::class);
}
/**
* Get the user that owns the phone.
*/
public function user()
{
return $this->belongsTo(App\User::class);
}
public $sortable = ['id', 'name', 'email', 'created_at', 'updated_at'];
public $sortable = ['address', 'phone_number'];
'uri_relation_column_separator' => '.'
class User extends Model
{
use Sortable;
public $sortable = ['name'];
...
public function addressSortable($query, $direction)
{
return $query->join('user_details', 'users.id', '=', 'user_details.user_id')
->orderBy('address', $direction)
->select('users.*');
}
...
...
$sortableAs = ['nick_name'];
...
$users = $user->select(['name as nick_name'])->sortable(['nick_name'])->paginate(10);