Problem with alphabetical ordering in the Aravel?

Asked

Viewed 60 times

0

I have a query in Aravel that lists me all the users that exist I want to sort by alphabetical order but the way I put that by the documentation of the Aravel and as I have done does not order anything

PHP

private function getChilds(array $elements, $parentId = 0) {

    $branch = array();

    foreach ($elements as $element) {
        if ($element['parent'] == $parentId) {
            $children = $this->getChilds($elements, $element['id']);
            if ($children) {
                foreach ($children as $child){
                    $branch[] = $child;
                }
            }
            $branch[] = $element;
        }
    }

    return $branch;
}

public function lista_jogadores (){

    $user_id = Auth::user()->id;

    $players = DB::table('players')->where('activo', '=', '1')->where('agent', '=', $user_id)->get();

    $childs = DB::table('agents')->select('id', 'username', 'parent')->orderBy('username', 'ASC')->get();
    $childs_arr = array();
    foreach ($childs as $child){
        $child_arr = array(
            'id' => $child->id,
            'username' => $child->username,
            'parent' => $child->parent
        );
        $childs_arr[] = $child_arr;
    }
    $parents = $this->getChilds($childs_arr, $user_id);

    return view('admin.templates.jogadores', ['players' => $players])->with('parents',$parents);

} 
  • Not enough to list anything? By the query you do should return a line, unless the authenticated user does not match the ativo = 1

  • Entire list only does not order

  • And the query Agents and not players I want to order

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.