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
BadMethodCallException:调用未定义的方法-laravel php_Php_Laravel - Fatal编程技术网

BadMethodCallException:调用未定义的方法-laravel php

BadMethodCallException:调用未定义的方法-laravel php,php,laravel,Php,Laravel,当我运行我的应用程序时,我得到下面的错误。在我的模型中,有一个名为text()的函数,但我仍然得到下面的错误。这个问题的原因是什么? 当我移除下面的Foreach循环时 `@foreach ($data->fill_texts as $t) <div>{{$t->text}} ({{$answer->text_count}})</div> @endforeach` 文本模型 public function texts() { retu

当我运行我的应用程序时,我得到下面的错误。在我的模型中,有一个名为
text()
的函数,但我仍然得到下面的错误。这个问题的原因是什么? 当我移除下面的Foreach循环时

`@foreach ($data->fill_texts as $t)
  <div>{{$t->text}} ({{$answer->text_count}})</div>
@endforeach` 
文本模型

  public function texts() {
    return $this->hasMany(Text::class);
  }

  public function fill_texts() 
  {    
    return $this->select('text', DB::raw('count(*) as text_count'))->texts()->groupBy('text')->get();  
  }
 protected $table = 'text';


    public function template() {
      return $this->belongsTo(Template::class);
    }
查看

  @forelse ($doc->templates as $data)
  @foreach ($data->fill_texts as $t)
      <div>{{$t->text}} ({{$answer->text_count}})</div>
    @endforeach
    @endforelse
@forelse($doc->模板作为$data)
@foreach($data->将文本填写为$t)
{{$t->text}}({{$answer->text_count})
@endforeach
@endforelse

您不能在该上下文中使用
文本。您可以尝试使用('text')
而不是
->text()
@aynber,我得到
未知列文本
。该列实际上位于
文本表中。我认为查询
->text()
将使我能够检索该columnNo
text()
将返回关系,因此它将是
$data
对象的属性。好的,这是有意义的。但是为什么我会得到错误
未知列文本
?该列是在模板表中还是文本表中?您正在使用的select将从templates表中获取数据,texts表关系将是一个单独的查询。