PHP code example of am2studio / laravel-table-sorter

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

    

am2studio / laravel-table-sorter example snippets


{{ \AM2Studio\Laravel\TableSorter\TableSorter::sort(
    [
      ['name' => 'first_name', 'title' => trans('ui.user.first_name')],
      ['name' => 'last_name',  'title' => trans('ui.user.last_name')],
      ['name' => 'gender',     'title' => trans('ui.user.gender')],
    ],
    $users,
    [
        'sort_by' => 'name', 'sort_type' => 'ASC',
        'template' => '<th class="%s"><a href="%s">%s</a></th>'
    ])
}}

[
  ['name' => 'first_name', 'title' => trans('ui.user.first_name')],
  ['name' => 'last_name',  'title' => trans('ui.user.last_name')],
  ['name' => 'gender',     'title' => trans('ui.user.gender')],
]

[
    'sort_by' => 'name', 'sort_type' => 'ASC',
    'template' => '<th class="%s"><a href="%s">%s</a></th>'
]

public function index()
{
    $users = (new User)->paginate(10);
    return $this->view('index', compact('users'));
}

<table>
	<thead>
		<tr>
			{{ \AM2Studio\Laravel\TableSorter\TableSorter::sort(
					[
						['name' => 'first_name', 'title' => trans('ui.user.first_name')],
						['name' => 'last_name',  'title' => trans('ui.user.last_name')],
						['name' => 'gender',     'title' => trans('ui.user.gender')],
					],
					$users,
					[
						'sort_by' => 'name', 'sort_type' => 'ASC',
						'template' => '<th class="%s"><a href="%s">%s</a></th>'
					])
			}}
		</tr>
	</thead>
	<tbody>
		@foreach($users as $user)
		<tr>

			<td>{{ $user->first_name }}</td>
			<td>{{ $user->last_name }}</td>
			<td>{{ $user->gender }}</td>
		</tr>
		@endforeach
	</tbody>
</table>
<div>{!! $users !!}</div>