は、私はそれはあなたのように、このリターン(外側左)LARAVEL
{
comment: "fdsfdsfsdffddsffds",
user_name: "ahmaf",
shop_name: "example.com",
rating: "4",
created_at: "2017-09-19 02:14:41",
images: https://example.com/kf/UT8.1.cX3XaXXagOFbX5.jpg
},
-{
comment: "fdsfdsfsdffddsffds",
user_name: "ahmaf",
shop_name: "example.com",
rating: "4",
created_at: "2017-09-19 02:14:41",
images: https://example.com/kf/UT81WzoX3BXXXagOFbXs.jpg
},
-{
comment: "sdfdsfdssfd",
user_name: "fdsfds",
shop_name: "example2.myshopify.com",
rating: "5",
created_at: "2017-09-19 02:12:25",
images: null
}
のような結果を返しますコメント
return $comments = \DB::table('comments')->select('comments.comment','comments.user_name','comments.shop_name',
'comments.rating','comments.created_at','comments_images.images')->
join('comments_images','comments.id','=','comments_images.comment_id','left outer')
->where('comments.product_id', '=', "11644254552")->
orderBy(\DB::raw('-`images`'), 'desc')->get();
に関連する画像を返すこのクエリをクエリ持っています最初の2行が重複していて、このように返されることを確認してください。
comment: "fdsfdsfsdffddsffds",
user_name: "ahmaf",
shop_name: "example.com",
rating: "4",
created_at: "2017-09-19 02:14:41",
images:{
0: https://example.com/kf/UT8.1.cX3XaXXagOFbX5.jpg
1: https://example.com/kf/UT81WzoX3BXXXagOFbXs.jpg
}
},
-{
comment: "sdfdsfdssfd",
user_name: "fdsfds",
shop_name: "example2.myshopify.com",
rating: "5",
created_at: "2017-09-19 02:12:25",
images: null
}
これは可能ですか?関連するデータごとに新しい行を作成する代わりに、それらを収集するように戻します。
それが働いたと私はみましたが、私はcomments_imagesテーブルから画像をORDERBY使うことができませんでした、それだけであなたは、親/子関係の結果を探しているコメント
$comments = Comment::where('product_id', '=', "11644215052")->with([
'images' => function ($query)
{
$query->orderBy('images', 'desc');
},
])->paginate(30);
'を追加するようにしてください - > GROUPBY( 'comments.id') - >()を取得;' !! – Maraboc
groupByは機能しません。その中にすべての列を追加する必要があります。そうしないとエラーが返され、すべてのレコードが返されません。私はちょうど重複した行をグループ化したい –