0
这里整理一组是我的查询:Laravel雄辩的元素
return App\AftermarketParts::where('alt', 'LIKE', "%$search%")
->orderBy('alt',"$direction")
->with('aftermarket_parts_type')
->get()
->groupBy('aftermarket_parts_type_id');
这里设置我的数据:
(16) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0:alt:(...)
created_at:(...)
deleted_at:(...)
id:(...)
image:(...)
image_height:(...)
image_width:(...)
link:(...)
tires_and_rims_type:Object
created_at:(...)
deleted_at:(...)
description:(...)
id:(...)
name:(...)
updated_at:(...)
1:{…}
2:{…}
我试图通过名对结果进行排序当然这不起作用。
return App\AftermarketParts::where('alt', 'LIKE', "%$search%")
->orderBy('alt',"$direction")
->orderBy('name',"$name_direction")
->with('aftermarket_parts_type')
->get()
->groupBy('aftermarket_parts_type_id');
我也曾尝试:
return DB::table('aftermarket_parts')
->join('aftermarket_parts_categories','aftermarket_parts_categories.id','=','aftermarket_parts.aftermarket_parts_type_id')
->select(DB::raw(
'aftermarket_parts.id,
aftermarket_parts.link,
aftermarket_parts.image,
aftermarket_parts.webpage_screen_shot,
aftermarket_parts.alt,
aftermarket_parts.image_width,
aftermarket_parts.image_height,
aftermarket_parts.aftermarket_parts_type_id,
aftermarket_parts.deleted_at,
aftermarket_parts.created_at,
aftermarket_parts.updated_at'))
->groupBy('name')
->orderBy('aftermarket_parts.alt', "$direction")
->orderBy('name', "$groupDirection")
->get();
返回数据集:
data:Array(80)
0:
aftermarket_parts_type_id:(...)
alt:(...)
created_at:(...)
deleted_at:(...)
id:(...)
image:(...)
image_height:(...)
image_width:(...)
link:(...)
updated_at:(...)
webpage_screen_shot:(...)
即使它返回订单正确它破坏对象的数组中的格式,我需要他们我想知道是否有办法通过雄辩的呼叫做到这一点,或者我应该只使用一个PHP排序数组?想法?先谢谢你。