In the screencast series “Building Data Tables”, the default order by appears to be ‘id’. Can someone provide guidance regarding how to set the order by to a different field (e.g.; name) in the controller?
Datatable Order By
Can you provide an example?
I can accomplish default ordering with a global scope on the model (as below), but was trying to figure out how to accomplish the same thing in the Livewire controller. I am probably overthinking it so will just go with the global scope.
protected static function boot()
{
parent::boot();
// Order by name ASC
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('name', 'asc');
});
}