Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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 OctoberCMS:管理双向多对多关系_Php_Laravel_Octobercms - Fatal编程技术网

Php OctoberCMS:管理双向多对多关系

Php OctoberCMS:管理双向多对多关系,php,laravel,octobercms,Php,Laravel,Octobercms,我正试图设计一本字典。各表如下: -语言 创建表meysam\U字典\U语言 id int无符号自动增量 主键, 标题varchar50不为空 -言语 创建表meysam\u字典\u单词 id int无符号自动增量 主键, 单词varchar500不为空, lang_id int无符号非空 -翻译 创建表meysam\u字典\u翻译 左\u字\u id int无符号非空, 右\u单词\u id int无符号非空, 说明varchar500不为空 现在每个词都有很多意思。因此,词与词之间存在着多对

我正试图设计一本字典。各表如下:

-语言 创建表meysam\U字典\U语言 id int无符号自动增量 主键, 标题varchar50不为空 -言语 创建表meysam\u字典\u单词 id int无符号自动增量 主键, 单词varchar500不为空, lang_id int无符号非空 -翻译 创建表meysam\u字典\u翻译 左\u字\u id int无符号非空, 右\u单词\u id int无符号非空, 说明varchar500不为空 现在每个词都有很多意思。因此,词与词之间存在着多对多的关系。此关系存储在翻译表中。以下是我的Word模型:

类词扩展模型 { 公共$belongsTo=[ “语言”=>[ “Meysam\Dictionary\Models\Language”, 'key'=>'lang\u id' ] ]; 公共$belongtomany=[ “含义”=>[ “Meysam\Dictionary\Models\Word”, “表”=>“meysam\u字典\u翻译”, 'key'=>'left\u word\u id', 'otherKey'=>'right\u word\u id' ], ]; } 考虑到上面的$belongtomany关系,在wordcontroller页面中,我只能看到单词ID位于Translations表中关系左侧时单词的含义。但是如果这个词在关系的右边,它的相关词就不会显示出来。有什么解决办法吗


我需要在控制器页面中显示一个单词的相关单词,而不管该单词位于翻译表中关系的左侧或右侧。

这是一个调整查询的问题,如果该关键字或其他关键字等于您的单词id,只需实现规则key 看看这篇文章,它使用相同的方法来声明两个用户之间的关系。

在该示例中,您将不需要action字段

查询如下所示

$languageId=1; $wordId=1; $query='SELECT*FROM words RIGHT JOIN SELECT`key`,other\u key FROM`meysam\u dictionary\u translations`WHERE`key`='.$wordId.'或`other\u key`='.$wordId.'AND language\u id='.$languageId.'as on words.id=r.key或words.id=r.other\u key WHERE workds.id!='$wordId