Having the following Laravel recursion in my model how do I avoid accidentally registered relation. What I mean: I have users and users can have many reportees and we want to get back the tree on a given user with the following snippet, which is works fine till the point if user is not a reportee to itself
/**
* User can have many Reporters
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function hasreporters()
{
return $this->belongsToMany('App\User', 'reporting_to', 'acc_receiving_from_id', 'acc_reporting_to_id')
->where('status', 'A');
}
/**
* @return $this
*/
public function children()
{
return $this->hasreporters()->with(['children']);
}
where can I check in the loop if a given id is not equal to the parent id
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire