1
0
Fork 0

更新 app/Admin/Services/BaseService.php

panliang 2023-12-01 14:36:19 +08:00
parent b019cafb71
commit c2c096ae7b
1 changed files with 20 additions and 6 deletions

View File

@ -19,7 +19,7 @@ class BaseService extends AdminService
public function getTree() public function getTree()
{ {
$list = $this->query()->orderByDesc('sort')->get()->toArray(); $list = $this->query()->get()->toArray();
return array2tree($list); return array2tree($list);
} }
@ -79,8 +79,8 @@ class BaseService extends AdminService
public function update($primaryKey, $data): bool public function update($primaryKey, $data): bool
{ {
$data = $this->resloveData($data);
$model = $this->query()->whereKey($primaryKey)->firstOrFail(); $model = $this->query()->whereKey($primaryKey)->firstOrFail();
$data = $this->resloveData($data, $model);
$validate = $this->validate($data, $model); $validate = $this->validate($data, $model);
if ($validate !== true) { if ($validate !== true) {
$this->setError($validate); $this->setError($validate);
@ -105,9 +105,10 @@ class BaseService extends AdminService
* 处理表单数据 * 处理表单数据
* *
* @param array $data * @param array $data
* @param Model $model : 添加, 非空: 修改
* @return array * @return array
*/ */
public function resloveData($data) public function resloveData($data, $model = null)
{ {
return $data; return $data;
} }
@ -121,6 +122,19 @@ class BaseService extends AdminService
*/ */
public function validate($data, $model = null) public function validate($data, $model = null)
{ {
// $createRules = [
// 'key' => ['required', Rule::unique('keywords', 'key')],
// 'name' => ['required'],
// ];
// $updateRules = [
// 'key' => [Rule::unique('keywords', 'key')->ignore($model->id)]
// ];
// $validator = Validator::make($data, $model ? $updateRules : $createRules, [
// 'key.unique' => ':input 已经存在'
// ]);
// if ($validator->fails()) {
// return $validator->errors()->first();
// }
return true; return true;
} }