本文整理汇总了PHP中Role::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::exists方法的具体用法?PHP Role::exists怎么用?PHP Role::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
function roles_post()
{
$requested_data = json_decode($this->post('models'));
foreach ($requested_data as $d) {
$user = new User(null, $this->entity);
$user->where('id', $d->user_id);
$user->get();
$role = new Role(null, $this->entity);
$role->where('id', $d->role_id);
$role->get();
if ($user->exists() && $role->exists()) {
if ($user->save($role)) {
$r = $user->include_related('role', NULL, TRUE)->get_raw();
$this->response(array('msg' => 'assigned successfully.', 'results' => $r->result()), 201);
} else {
$this->response(array('msg' => 'error assigning to role.', 'results' => array()), 201);
}
} else {
$this->response(array('msg' => 'either role or user does not exist', 'results' => array()), 201);
}
}
// $this->response(array('msg'=>'assigned successfully.', 'results'=>$r->result()), 201);
}
示例2: foreach
function user_put()
{
$model = json_decode($this->put('models'));
foreach ($model as $d) {
$user = new User(null, $this->entity);
$user->where('id', $d->user);
$user->get();
$role = new Role(null, $this->entity);
$role->where('id', $d->role);
$role->get();
if ($user->exists() && $role->exists()) {
$user->set_join_field($role, 'role_id', $d->role);
if ($user->save($role)) {
$this->response(array('msg' => 'assigned'), 201);
}
}
// $this->response(array('user'=>$user->id), 201);
}
// $this->response(array('user'=>$model[0]->user), 201);
}
示例3: remove_role_from_user
/**
* Remove Role From User
* Removes a role from a user
*
* @param mixed $user_id
* @param mixed $role_id
*/
public function remove_role_from_user($user_id, $role_id)
{
$u = new User($user_id);
$r = new Role($role_id);
if ($u->exists() and $r->exists()) {
$u->delete($r);
}
}