Newly created resources do not get sorted.
Closed this issue · 1 comments
jenskuipers commented
I implemented column-sortable on a couple of resources, in the Laravel 8 application that I am working on. It works like a charm. However; there is some kind of error.
New resources do not get sorted and stay on top, but the seeded resources do get sorted. In the code fragments below I'm showing the post resource.
Post model:
public $sortable = [
'title',
'updated_at',
];
User model:
public $sortable = [
'name',
'email',
'created_at'
];
Category model:
public $sortable = [
'name'
];
Controller:
public function index(Request $request)
{
$posts = Post::orderBy('updated_at', 'desc')
->sortable(['title', 'user.name', 'updated_at', 'category.name'])
->paginate(12);
return View::make('post.index', compact('posts'));
}
View:
<table class="table">
<thead>
<th class="col-md-4">@sortablelink('title', 'Title')</th>
<th class="col-md-2">@sortablelink('user.name', 'Author')</th>
<th class="col-md-3">@sortablelink('updated_at', 'Last change')</th>
<th class="col-md-3">@sortablelink('category.name', 'Category')</th>
</thead>
@foreach($posts as $post)
<tr>
<td><a href="{{ route('post.show', $post) }}">{{ $post->title }}</a></td>
<td><em><a href="{{ route('user.show', $post->user->id) }}">{{ $post->user->name }}</a></em></td>
<td>{{ $post->updated_at }}
<td><a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a></td>
</tr>
@endforeach
</table>
Is there anything that I might be missing?
jenskuipers commented
I solved it while implementing repositories in Laravel. This was probably a human error. Solved, but no explanation why.