代码之家  ›  专栏  ›  技术社区  ›  Jim

拉维尔背包,关系出了差错

  •  0
  • Jim  · 技术社区  · 7 年前

    我有一个国家和一个大陆的表。这些国家有一个“大陆id”字段。国家模式有一种方法:

    public function getContinent()
          {
            return $this->belongsTo('App\Models\Continent','continent_id','id');
          }
    

    如果我用tinker测试一下,我会得到正确的答案:

    $co = App\Models\Country::with('getContinent)->first()
    

    enter image description here

    在CountryCrudController上的设置中,我想添加一个显示大陆的字段,并且我还想将7个大陆中的一个选择添加到国家编辑中,因此在列表部分我定义了:

      $this->crud->addColumn([
          'name' => "continent",
          'label' => "continent", // Table column heading
          'type' => "select",
          'entity' => 'getContinent ', // the method in your Model
          'attribute' => 'continent',
        ]);
    

    但当我试着运行它时,我得到:

    enter image description here

    请问我做错了什么?

    1 回复  |  直到 7 年前
        1
  •  0
  •   tabacitu    7 年前

    在getContinent之后你还有空间 -那肯定不应该在那里。

    名称 大陆 ,不是 大陆 .

      $this->crud->addColumn([
          'name' => "continent_id",
          'label' => "Continent", // Table column heading
          'type' => "select",
          'entity' => 'getContinent', // the method in your Model
          'attribute' => 'continent',
        ]);
    

    推荐文章