refactor(admin): AdminFlash增加apply并在批量动作成功提示复用
This commit is contained in:
@@ -57,4 +57,39 @@ class AdminFlash
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 payload 批量 apply 到 redirect response(统一 session key 处理口径)。
|
||||
*
|
||||
* @param object $redirect 需提供 ->with($key,$value)
|
||||
*/
|
||||
public static function apply(object $redirect, array $payload): object
|
||||
{
|
||||
$alwaysKeys = ['success', 'warning', 'error'];
|
||||
|
||||
foreach ($payload as $k => $v) {
|
||||
$k = (string) $k;
|
||||
|
||||
if (in_array($k, $alwaysKeys, true)) {
|
||||
$redirect = $redirect->with($k, $v);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($v === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_string($v)) {
|
||||
if (trim($v) === '') {
|
||||
continue;
|
||||
}
|
||||
$redirect = $redirect->with($k, $v);
|
||||
continue;
|
||||
}
|
||||
|
||||
$redirect = $redirect->with($k, $v);
|
||||
}
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user