/** * Định nghĩa quyền vào bảng authItem * @param type $data */ public static function authItemSave($data) { $item = self::findOne(['name' => $data['name']]); if (empty($item)) { $item = new AuthItem(); $item->created_at = time(); $item->description = 'Hệ thống cập nhật'; $item->type = $data['type']; $item->name = $data['name']; } $item->updated_at = time(); $item->alias = $data['alias']; $item->group_id = isset($data['group']) ? $data['group'] : 0; if (!$item->save()) { return new Response(false, "Định nghĩa quyền không thành công", $item->errors); } $par = explode("_", $data['name'])[0]; if (strpos($data['name'], "_") && self::getAuthItemChildsByPrimarykey($par, $data['name']) == null) { $authItemChild = new AuthItemChild(); $authItemChild->parent = $par; $authItemChild->child = $data['name']; $authItemChild->save(); } return $item; }