Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Kyslik\ColumnSortable\Sortable;
class Exam_sched extends Model
{
use Sortable;
protected $fillable = ['date', 'startTime', 'endTime', 'roomNo', 'batch_id', 'subject_id'];
public $sortable = [
'id', 'date', 'startTime', 'endTime', 'roomNo', 'batch_id', 'subject_id', 'created_at'
];
public function subject(){
return $this->belongsTo('\App\Subject','subject_id');
}
public function batch(){
return $this->belongsTo('\App\Batch','batch_id');
}
}
Controller:
public function index()
{
$exam_scheds= Exam_sched::sortable()->paginate(3);
return view('examschedule',compact('exam_scheds'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$exam_scheds=Exam_sched::sortable()->paginate(3);
$subjects=Subject::all();
$batches=Batch::all();
return view('examschedule', compact('exam_scheds','subjects','batches'));
}
view Blade:
<div class="row schedule-form">
<div class="col-lg-10 offset-lg-1">
<table class="table table-striped ">
<thead>
<tr class="thead">
<th style="width: 150px">@sortablelink('Exam Date')</th>
<th style="width: 100px">@sortablelink('Batch')</th>
<th style="width: 100px">@sortablelink('Subject')</th>
<th style="width: 110px">@sortablelink('Room No')</th>
<th>@sortablelink('Start Time')</th>
<th>@sortablelink('End Time')</th>
<th>@sortablelink('Created At')</th>
@auth
@if(Auth::user()->role_id == 1)
<th>Action</th>
@endif
@endauth
</tr>
</thead>
<tbody>
@if($exam_scheds->count())
@foreach($exam_scheds as $exam_sched)
<tr class="tbody">
<td>{{$exam_sched->date}}</td>
<td>{{$exam_sched->batch->name}}</td>
<td>{{$exam_sched->subject->name}}</td>
<td>{{$exam_sched->roomNo}}</td>
<td>{{$exam_sched->startTime}}</td>
<td>{{$exam_sched->endTime}}</td>
<td>{{$exam_sched->created_at->diffForHumans()}}</td>
</tr>
@endforeach
@endif
</tbody>
</table>
{!! $exam_scheds->appends(\Request::except('page'))->render() !!}
</div>
App.Php:
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
/*
* Package Service Providers...
*/
Kyslik\ColumnSortable\ColumnSortableServiceProvider::class,
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
Kyslik/column sortable package, sort is not working but pagination is okay. Anyone here Please help me ...thank you!
Kyslik/column sortable package, sort is not working but pagination is okay. Anyone here Please help me ...thank you! Kyslik/column sortable package, sort is not working but pagination is okay. Anyone here Please help me ...thank you!
@sortablelink first parameter is your column in the database name and the second parameter is the name that will be rendered in your view.
See the example here: https://github.com/Kyslik/column-sortable-example/blob/L5.8/resources/views/user.blade.php
So your
@sortablelink('Exam Date')should be@sortablelink('date', 'Exam Date')