Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何根据标题和关系排序_Php_Laravel - Fatal编程技术网

Php 如何根据标题和关系排序

Php 如何根据标题和关系排序,php,laravel,Php,Laravel,我有以下查询:$scholen=scholen::带有“媒体”、“翻译”、“seo”->在线 当我将其转储时: 如何从关系->翻译->字段中按“标题”对学校进行排序 提前谢谢 Olivier您可以使用$scholen[$index]->translations[$index]->字段访问字段,但是您无法访问title属性,因为字段的整个值是一个字符串-您必须去掉字符串才能获得所需的位 您必须获取查询的结果,然后通过在sortBy回调中包含此逻辑对结果进行排序,例如 $scholen->s

我有以下查询:$scholen=scholen::带有“媒体”、“翻译”、“seo”->在线

当我将其转储时:

如何从关系->翻译->字段中按“标题”对学校进行排序

提前谢谢

Olivier

您可以使用$scholen[$index]->translations[$index]->字段访问字段,但是您无法访问title属性,因为字段的整个值是一个字符串-您必须去掉字符串才能获得所需的位

您必须获取查询的结果,然后通过在sortBy回调中包含此逻辑对结果进行排序,例如

$scholen->sortBy(function ($value, $key) {
    // Logic here to get the part of the `fields` string you want
    // and then sort it
});
希望这有帮助,这看起来有点棘手