2017-07-13 8 views
1

私はLaravel 5.2を使用していますが、私は以下のように雄弁を持っている:これは以下のようなデータを返しているエイリアス列名は

return $this->with('useType')->with('distributionChannelType') 
        ->with('commercialModelType')->with('deliveryChannel') 
        ->with('territoryCode')->with('mobileOperatorCode')->with('serviceCode') 
        ->where('content_partner_id', $cp_id)->get()->toArray(); 

:このデータに

[ 
{ 
"id": 36, 
"created_at": "2017-07-12 08:43:13", 
"usetype": [ 
{ 
"revenue_share_id": 36, 
"use_type_id": 39, 
"use_type": "UseAsRingbackTune", 
"definition": "To Use a Resource in a Release as ringbacktune." 
}, 
{ 
"revenue_share_id": 36, 
"use_type_id": 31, 
"use_type": "Stream", 
"definition": "To stream a Resource" 
} 
], 
"commercialmodeltypes": [ 
{ 
"revenue_share_id": 36, 
"commercial_model_type_id": 5, 
"commercial_model_type": "PayAsYouGoModel" 
} 
], 
"deliverychannels": [ 
{ 
"revenue_share_id": 36, 
"delivery_channel_id": 1, 
"delivery_channel": "Desktop App" 
} 
], 
"territorycodes": [ 
{ 
"revenue_share_id": 36, 
"territory_code_id": 250, 
"revenue_share": "43.00", 
"territory_code": "Africa" 
} 
], 
"mobileoperatorcodes": [ 
{ 
"revenue_share_id": 36, 
"mobile_operator_code_id": 2, 
"revenue_share": "43.00", 
"mobile_operator_code": "Benin (Glo Mobile)" 
} 
], 
"servicecodes": [ 
{ 
"revenue_share_id": 36, 
"service_code_id": 7, 
"revenue_share": "87.00", 
"service_code": "Artist Pack" 
} 
], 
"languagecodes": [ 
{ 
"revenue_share_id": 36, 
"language_code_id": 3, 
"revenue_share": "0.00", 
"language_code": "French(fr)" 
} 
] 
} 
] 

私は別名列にしたいです例えば名前:

use_type_id AS ID

use_type ASラベル

どうすればいいですか?私はすべての反応に感謝します。先にありがとう。

答えて

1
return $this->with('useType AS id or any name you want to give')->with('distributionChannelType') 
        ->with('commercialModelType')->with('deliveryChannel') 
        ->with('territoryCode')->with('mobileOperatorCode')->with('serviceCode') 
        ->where('content_partner_id', $cp_id)->get()->toArray(); 

実際usetypeには関数であり、私は列名をエイリアスしたいこの

public function useType() { return $this->belongsToMany('App\UseType', 'UsageRightUseTypes')->withPivot('usage_right_id', 'use_type_id as some_name'); } 
+0

を試してみてください。私はこれを試してみると、結果に変化はありません。 –

+0

関数を呼び出してデータベースからデータを取得する場所で使用する – Exprator

+0

public function useType(){ return $ this-> belongsToMany( 'App \ UseType'、 'UsageRightUseTypes') - > withPivot( 'usage_right_id'、 ' use_type_id '); } これは機能です。どこで使うことができますか?手伝って頂けますか? –

関連する問題