本文整理匯總了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);
}
}