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);
            return $this;
        }

        // 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 ('asc' == $sort_type) {
                return $f > $s ? 1 : -1;
            }

            return $f < $s ? 1 : -1;
        });

        return $this;
    }
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);
            return $this;
        }

        // 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 ('asc' == $sort_type) {
                return $f > $s ? 1 : -1;
            }

            return $f < $s ? 1 : -1;
        });

        return $this;
    }
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 ) ; return $ this ; } // 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 ( 'asc' == $ sort_type ) { return $ f > $ s ? 1 : - 1 ; } return $ f < $ s ? 1 : - 1 ; } ) ; return $ this ; }
Sorts the menu based on user's callable.

@param string|callable $sort_type

@return Builder
Sorts the menu based on user s callable .