If you tried to order dates using the DataTables component, you may have struggled for a wile.
I've found the final solution to all these problems: using the data-order attribute to specify the date in yyyy-mm-dd format:
<td data-order="{{ \Carbon\Carbon::parse($pacient->created_at)->format('Y-m-d H:i') }}">
{{ $pacient->formatted_created_at }}
</td>
Then, you can simply order by that column in the JavaScript code, and, that's all folks!
PS: I have in my Patient model this definition:
public function getFormattedCreatedAtAttribute()
{
return $this->created_at->format('d-m-Y');
}
Top comments (0)