no message
This commit is contained in:
parent
4ef0f285e7
commit
f5853f780d
@ -239,16 +239,9 @@ public function hit(Request $oRequest)
|
||||
$iId = request('id');
|
||||
$sField = request('field');
|
||||
|
||||
$sFieldType = $this->aFieldTypes[$sField] ?? '';
|
||||
|
||||
$sHit = $this->oModel->find($iId)?->{$sField};
|
||||
if (is_array($sHit)) {
|
||||
$sHit = json_encode($sHit);
|
||||
}
|
||||
|
||||
if ($sFieldType == 'json') {
|
||||
$sHit = json_decode($sHit, true);
|
||||
$sHit = json_encode($sHit, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
$sHit = json_encode($sHit, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
@ -302,6 +295,8 @@ public function detailSave(Request $oRequest)
|
||||
|
||||
unset($aParams['id'], $aParams['_method']);
|
||||
|
||||
$aCasts = $oThisModel->getCasts();
|
||||
|
||||
foreach ($aParams as $k => &$v) {
|
||||
if (empty($v) && empty($oThisModel->{$k})) {
|
||||
continue;
|
||||
@ -309,12 +304,22 @@ public function detailSave(Request $oRequest)
|
||||
if (empty($v) && $v !== 0 && $v !== '0') {
|
||||
$v = '';
|
||||
}
|
||||
|
||||
$sCastType = $aCasts[$k] ?? null;
|
||||
if (in_array($sCastType, ['array', 'json', 'collection'], true) && is_string($v)) {
|
||||
// 如果传入的是字符串,手动解码为数组,防止 Eloquent 在 save 时二次转义
|
||||
$aDecoded = json_decode($v, true);
|
||||
// if (json_last_error() === JSON_ERROR_NONE && is_array($aDecoded)) {
|
||||
$v = $aDecoded;
|
||||
// }
|
||||
}
|
||||
|
||||
if ($oThisModel->{$k} != $v) {
|
||||
$oThisModel->{$k} = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$oThisModel->save();
|
||||
$oThisModel->save(); // 在这里保存的aOpt,如何避免被转译
|
||||
|
||||
$aChangeField = $oThisModel->getChanges();
|
||||
|
||||
@ -464,7 +469,14 @@ public function index(Request $oRequest)
|
||||
$oQuery->orderBy($aOrderBy['sField'], $aOrderBy['sSort']);
|
||||
}
|
||||
|
||||
$oPaginatedData = $oQuery->paginate($iLimit);
|
||||
$oPaginatedData = $oQuery->paginate($iLimit); // 倾向方案2
|
||||
|
||||
// $oPaginatedData->getCollection()->transform(function ($oArticle) {
|
||||
// // 强制将模型属性还原为未经 Cast 处理的原始字典
|
||||
// $oArticle->setRawAttributes($oArticle->getRawOriginal());
|
||||
//
|
||||
// return $oArticle;
|
||||
// });
|
||||
// tt($oPaginatedData);
|
||||
// $oPaginatedData = $oQuery->paginate($iLimit, array_keys($this->aListFields));
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ final class CategoryBaseController extends ListController
|
||||
// 'schema_pro' => 'text',
|
||||
// 'cmd' => 'text',
|
||||
// 'cmd_log' => 'text',
|
||||
'aBanner' => 'json'
|
||||
// 'aBanner' => 'array'
|
||||
];
|
||||
|
||||
protected array $aOrderBy = [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user