Php 如何根据标题和关系排序
我有以下查询:$scholen=scholen::带有“媒体”、“翻译”、“seo”->在线 当我将其转储时: 如何从关系->翻译->字段中按“标题”对学校进行排序 提前谢谢 Olivier您可以使用$scholen[$index]->translations[$index]->字段访问字段,但是您无法访问title属性,因为字段的整个值是一个字符串-您必须去掉字符串才能获得所需的位 您必须获取查询的结果,然后通过在sortBy回调中包含此逻辑对结果进行排序,例如Php 如何根据标题和关系排序,php,laravel,Php,Laravel,我有以下查询:$scholen=scholen::带有“媒体”、“翻译”、“seo”->在线 当我将其转储时: 如何从关系->翻译->字段中按“标题”对学校进行排序 提前谢谢 Olivier您可以使用$scholen[$index]->translations[$index]->字段访问字段,但是您无法访问title属性,因为字段的整个值是一个字符串-您必须去掉字符串才能获得所需的位 您必须获取查询的结果,然后通过在sortBy回调中包含此逻辑对结果进行排序,例如 $scholen->s
$scholen->sortBy(function ($value, $key) {
// Logic here to get the part of the `fields` string you want
// and then sort it
});
希望这有帮助,这看起来有点棘手