public function sortBy($sort_by, $sort_type = 'asc')
{
if (is_callable($sort_by)) {
$rslt = call_user_func($sort_by, $this->items->toArray());
if (!is_array($rslt)) {
$rslt = array($rslt);
}
$this->items = new Collection($rslt);
}
// running the sort proccess on the sortable items
$this->items = $this->items->sort(function ($f, $s) use($sort_by, $sort_type) {
$f = $f->{$sort_by};
$s = $s->{$sort_by};
if ($f == $s) {
return 0;
}
if ($sort_type == 'asc') {
return $f > $s ? 1 : -1;
}
return $f < $s ? 1 : -1;
});
return $this;
}