I am trying to get a result of query relation using relation methods in Laravel11 model
Department table has a field named parent and it’s default value is 0
I write an if statement but it always return the else result
here is my code
`class Department extends Model
{
use HasFactory;
public function members(){
if($this->parent==0)
return $this->hasManyThrough(
Profile::class,
Department::class,
'parent',
'department_id'
);
else
return $this->hasMany(Profile::class,'department_id');
}
}`
New contributor
Eng.Mokhtar Ghaleb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.