I get the below error when i run my application.In my model, there is a function called texts()
but still i'm getting the below error. What is the cause of this problem? When i remove the Foreach loop below
`@foreach ($data->fill_texts as $t)
<div>{{$t->text}} ({{$answer->text_count}})</div>
@endforeach`
It works fine with out any error.
BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::texts()
Template Model
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();
}
Text Model
protected $table = 'text';
public function template() {
return $this->belongsTo(Template::class);
}
View
@forelse ($doc->templates as $data)
@foreach ($data->fill_texts as $t)
<div>{{$t->text}} ({{$answer->text_count}})</div>
@endforeach
@endforelse