に返された結果をリファクタリングするピボットテーブルを持つ多くの雄弁多くそれはDEVICE_IDなどの特定field.suchに基づいてI行を返す関数を持っている私は記憶データが他の三つのテーブル</p> <p><a href="https://i.stack.imgur.com/2tBy1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2tBy1.png" alt="Table"></a></p> <p>を同期させることがピボットテーブルを持っている特定のアレイ
public function getDeviceReleasesByProfileId($profile_id)
{
try {
$profile = Profile::find($profile_id);
if (!$profile) {
return $this->respondNotFound('Profile not found');
}
$profile_releases = DeviceProfileRelease::where('profile_id', '=', $profile_id)->get();
// Refactor to array here.
return $this->respondWithSuccess($profile_releases);
} catch (\Exception $error) {
return $this->respondInternalError($error->getMessage());
}
}
私は何をする必要があることは、現在 [ { "device_id": 19, "profile_id": 7, "release_id": 1 }, { "device_id": 19, "profile_id": 7, "release_id": 2 }, { "device_id": 19, "profile_id": 7, "release_id": 3 }, { "device_id": 19, "profile_id": 7, "release_id": 4 } ]
これらの結果のそれぞれについて、 $profile_releases->release()->get()
メソッドを使用して、ピボットされた値の配列ではなく、リリースのリストに結果を変更します。私の質問は、私は間違った方法でピボットテーブルを設計し、最適なパフォーマンスとより良いコードのためにこれをリファクタリングする方法があるということです。
私はちょうど誰もがより良いアプローチについてどのような他のアイデアを持っているかどうかを確認したい
$releases = array();
foreach ($profile_releases as $profile_release)
{
$release_search = Release::find($profile_release->release_id);
$releases[] = $release_search;
}
、それは次のように行うことができます知っている、これは間違った