更新 app/Admin/Services/BaseService.php
parent
b019cafb71
commit
c2c096ae7b
|
|
@ -19,7 +19,7 @@ class BaseService extends AdminService
|
|||
|
||||
public function getTree()
|
||||
{
|
||||
$list = $this->query()->orderByDesc('sort')->get()->toArray();
|
||||
$list = $this->query()->get()->toArray();
|
||||
|
||||
return array2tree($list);
|
||||
}
|
||||
|
|
@ -79,8 +79,8 @@ class BaseService extends AdminService
|
|||
|
||||
public function update($primaryKey, $data): bool
|
||||
{
|
||||
$data = $this->resloveData($data);
|
||||
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
|
||||
$data = $this->resloveData($data, $model);
|
||||
$validate = $this->validate($data, $model);
|
||||
if ($validate !== true) {
|
||||
$this->setError($validate);
|
||||
|
|
@ -103,30 +103,44 @@ class BaseService extends AdminService
|
|||
|
||||
/**
|
||||
* 处理表单数据
|
||||
*
|
||||
*
|
||||
* @param array $data
|
||||
* @param Model $model 空 : 添加, 非空: 修改
|
||||
* @return array
|
||||
*/
|
||||
public function resloveData($data)
|
||||
public function resloveData($data, $model = null)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
*
|
||||
*
|
||||
* @param array $data
|
||||
* @param Model $model 空: 添加, 非空: 修改
|
||||
* @return mixed true: 验证通过, string: 错误提示
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除的前置方法
|
||||
*
|
||||
*
|
||||
* @param array $ids 主键id
|
||||
* @return mixed true: 继续后续操作, string: 中断操作, 返回错误提示
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue