Laravel-Administrator 的关联表查询怎么用啊

看了文档说,用法如下

'user_name' => [
        //     'title' => "Author",
        //     'relationship' => 'user', //this is the name of the Eloquent relationship method!
        //     'select' => "(:table).name",
        // ],

我写的代码如下:

'user_id' => [
            'title' => '作者',
            'relationship' => 'users', //this is the name of the Eloquent relationship method!
            'select' => "(:table).name",
        ],

我要在topics里靠user_id查对应的users表里的id=user_id的name字段的值

但是我写以后,就是http500报错,有几个问题:

  1. relationship 是不是关联表的名称??
  2. (:table)要不是改成关联表的名称??
  3. (:table).name里的name是不是管理表的字段???

注:各种belongsTo hasMany应该是正确的,因为前端是能查出我想要的东西的

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

下午分析了一下,应该是下面这样:

'user_name' => [
            'title' => '作者',
            'relationship' => 'user', //this is the name of the Eloquent relationship method!
            'select' => "(:table).name",
        ],

//user_name 是自定义的列
// 'relationship' => 'user' 英文解释说的很明白,就是Eloquent里的belongsTo那个方法的名字
//'select' => "(:table).name", 就是关联表的字段的名字,table不用改

但是,火大。。。demo里是可以用的,搬过来就不行,所以。。。。。难道是不支持5.8????

报错信息:

BadMethodCallException
Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsTo::getOtherKey()
4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!