Back

avoid duplicated statements when role is checked


Hello,

I have a method "hasRole" in my User model to check the user role which do the following : ``` if ($this->roles()->where('name',$role)->first()) {return true;}

It is called via a policy class by a view using several @can tags.
The problem is that it generate duplicated statements to users/roles tables when the view is loaded.
How can I solve it ?  Is it possible to make, e.g., an eager load of the role when the user authenticates ?

Thank you in advance

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us