更新 app/Admin/Services/BaseService.php
parent
b019cafb71
commit
c2c096ae7b
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue