Answer the question
In order to leave comments, you need to log in
Is it possible to exclude find for WithCount?
I check the quantity through withcount. Made in the model
public function hasModel($model)
{
if ($this->withCount($model)->find($this->id)->{$model.'_count'}>0) return true;
return false;
}
public function hasModel($model)
{
if ($this->$model()->count()>0) return true;
return false;
}
Answer the question
In order to leave comments, you need to log in
It is necessary to call not the model, but the relation function
public function hasModel($relation)
{
return $this->$relation()->count()>0;
}
public function comments()
{
return $this->hasMany('App\Comment');
}
...
$this->hasModel('comments')
public function comments()
{
return $this->hasMany('App\Comment');
}
...
$this->has('comments')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question