我使用的是laravel 4.2,如何按降序输出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更新*/
也许我应该换成下面的型号?(project/app/model/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;
}发布于 2018-12-27 15:11:02
你应该试试这个:
public function index() {
$member = $this->getMember ();
$transitions = $member->orderBy('id','desc')->getTransitions ();
return ResponseWrapper::toJson ( $transitions );
}发布于 2018-12-27 15:20:39
试试这个,
public function index() {
$member = $this->getMember ();
$transitions = $member->getTransitions()->orderBy('id','desc')->get();
return ResponseWrapper::toJson ( $transitions );
}发布于 2018-12-27 15:21:35
用于Laravel V4的 :
$transitions = $member::orderBy('id', 'DESC')->getTransitions();https://stackoverflow.com/questions/53941105
复制相似问题