默認的字典名: dict_name是有下劃線,添加和編輯一直提示錯誤: 字典名稱只能是字母數(shù)字的組合
在正則校驗規(guī)則中修改成 "/^[a-zA-Z0-9_]+$/"
/**
* 插入
* @param Request $request
* @return Response
* @throws BusinessException|Throwable
*/
public function insert(Request $request): Response
{
if ($request->method() === 'POST') {
$name = $request->post('name');
if (Dict::get($name)) {
return $this->json(1, '字典已經(jīng)存在');
}
if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) {
return $this->json(2, '字典名稱只能是字母數(shù)字的組合');
}
$values = (array)$request->post('value', []);
Dict::save($name, $values);
}
return raw_view('dict/insert');
}
/**
* 更新
* @param Request $request
* @return Response
* @throws BusinessException|Throwable
*/
public function update(Request $request): Response
{
if ($request->method() === 'POST') {
$name = $request->post('name');
if (!Dict::get($name)) {
return $this->json(1, '字典不存在');
}
if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) {
return $this->json(2, '字典名稱只能是字母數(shù)字的組合');
}
Dict::save($name, $request->post('value'));
}
return raw_view('dict/update');
}
webman2.1,webman_admin2.0