Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在用户和用户角色之间有多对多的关系,我想检查用户是否具有给定的角色,例如
if ($user->belongs($role->id)) doSomething();
但我在文档中找不到它。
是否有这样一种快捷方式来检查给定模型是否具有关系,或本机 L4 方法?
这应该对你有用
//get the attached roles of someuser $someusers_roles = $someuser->related()->lists('role_id'); //check if he has a particular role attached if(in_array($particular_role->id, $someusers_roles)) { doSomething(); }
希望这可以帮助你。