laravel 4 输出json顺序desc

问题描述 投票:0回答:3

我使用 Laravel 4.2 如何按 desc 顺序输出 json?谢谢。

下面是我的代码:

public function show($id) {
    $member = $this->getMember ();
    $transition = $member->getTransition ( $id )->first ();
    $transition_info = $transition-> transitionInfo;
    return ResponseWrapper::toJson ( $transition_info );
}

...

public function index() {
    $member = $this->getMember ();
    $transitions = $member->getTransitions ();

    return ResponseWrapper::toJson ( $transitions );
}

/* 12/28 更新 */

也许我应该更改以下型号? (项目/应用程序/模型/Member.php)

public function getTransitions() 

{
$array = $this->hasMany('Transition', 'payeer_id', 'id')->select($this->transition_index_payeer_column)->get()->all();

$arrayb = $this->hasMany('Transition', 'remitter_id', 'id')->select($this->transition_index_remitter_column)->whereRaw('NOT (card_type_remitter = "focas" and focas_status = "")')->get()->all();

$reuslt = array_merge ( $array, $arrayb );
return $reuslt;
}
json laravel laravel-4 sql-order-by
3个回答
0
投票

你应该尝试这个:

public function index() {

    $member = $this->getMember ();
    $transitions = $member->orderBy('id','desc')->getTransitions ();

    return ResponseWrapper::toJson ( $transitions );

}

0
投票

试试这个,

public function index() {

    $member = $this->getMember ();
    $transitions = $member->getTransitions()->orderBy('id','desc')->get();

    return ResponseWrapper::toJson ( $transitions );

}

0
投票

对于 Laravel V4 :

 $transitions = $member::orderBy('id', 'DESC')->getTransitions();
© www.soinside.com 2019 - 2024. All rights reserved.