diff --git a/resources/views/partials/alerts.blade.php b/resources/views/partials/alerts.blade.php index d34eb8874..cd769bd73 100755 --- a/resources/views/partials/alerts.blade.php +++ b/resources/views/partials/alerts.blade.php @@ -1,8 +1,8 @@ @if($error = session()->get('error'))
-

 {{ \Illuminate\Support\Arr::get($error->get('title'), 0) }}

-

{!! \Illuminate\Support\Arr::get($error->get('message'), 0) !!}

+

 {{ $error->getTitle() }}

+

{!! $error->getMessage() !!}

@elseif ($errors = session()->get('errors')) @if ($errors->hasBag('error')) @@ -19,23 +19,23 @@ @if($success = session()->get('success'))
-

 {{ \Illuminate\Support\Arr::get($success->get('title'), 0) }}

-

{!! \Illuminate\Support\Arr::get($success->get('message'), 0) !!}

+

 {{ $success->getTitle() }}

+

{!! $success->getMessage() !!}

@endif @if($info = session()->get('info'))
-

 {{ \Illuminate\Support\Arr::get($info->get('title'), 0) }}

-

{!! \Illuminate\Support\Arr::get($info->get('message'), 0) !!}

+

 {{ $info->getTitle() }}

+

{!! $info->getMessage() !!}

@endif @if($warning = session()->get('warning'))
-

 {{ \Illuminate\Support\Arr::get($warning->get('title'), 0) }}

-

{!! \Illuminate\Support\Arr::get($warning->get('message'), 0) !!}

+

 {{ $warning->getTitle() }}

+

{!! $warning->getMessage() !!}

@endif \ No newline at end of file diff --git a/resources/views/partials/exception.blade.php b/resources/views/partials/exception.blade.php index fb3069f03..004903303 100755 --- a/resources/views/partials/exception.blade.php +++ b/resources/views/partials/exception.blade.php @@ -1,11 +1,16 @@ @if(isset($errors) && $errors->hasBag('exception')) - getBag('exception'); ?> + @php + $error = $errors->getBag('exception'); + $errorType = $error->first('type'); + $errorFile = $error->first('file'); + $errorLine = $error->first('line'); + @endphp

- {{ class_basename($error->get('type')[0]) }} - In {{ basename($error->get('file')[0]) }} line {{ $error->get('line')[0] }} : + {{ class_basename($errorType) }} + In {{ basename($errorFile) }} line {{ $errorLine }} :

  {!! $error->first('message') !!}

diff --git a/resources/views/partials/toastr.blade.php b/resources/views/partials/toastr.blade.php index e9512face..ac6a2b83c 100644 --- a/resources/views/partials/toastr.blade.php +++ b/resources/views/partials/toastr.blade.php @@ -1,9 +1,9 @@ @if(Session::has('dcat-admin-toastr')) @php $toastr = Session::get('dcat-admin-toastr'); - $type = $toastr->get('type')[0] ?? 'success'; - $message = $toastr->get('message')[0] ?? ''; - $options = admin_javascript_json($toastr->get('options', [])); + $type = $toastr->getTitle(); + $message = $toastr->getMessage(); + $options = admin_javascript_json($toastr->getOptions()); @endphp @endif \ No newline at end of file diff --git a/src/Http/Controllers/ScaffoldController.php b/src/Http/Controllers/ScaffoldController.php index 312affa31..c4a97cce6 100644 --- a/src/Http/Controllers/ScaffoldController.php +++ b/src/Http/Controllers/ScaffoldController.php @@ -11,13 +11,13 @@ use Dcat\Admin\Scaffold\ModelCreator; use Dcat\Admin\Scaffold\RepositoryCreator; use Dcat\Admin\Support\Helper; +use Dcat\Admin\Support\SessionMessage; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\URL; -use Illuminate\Support\MessageBag; use Illuminate\Support\Str; class ScaffoldController extends Controller @@ -275,10 +275,7 @@ protected function getDatabaseColumns($db = null, $tb = null) protected function backWithException(\Exception $exception) { - $error = new MessageBag([ - 'title' => 'Error', - 'message' => $exception->getMessage(), - ]); + $error = SessionMessage::make('Error', $exception->getMessage()); return redirect()->refresh()->withInput()->with(compact('error')); } @@ -293,10 +290,7 @@ protected function backWithSuccess($paths, $message) $messages[] = "
$message"; - $success = new MessageBag([ - 'title' => 'Success', - 'message' => implode('
', $messages), - ]); + $success = SessionMessage::make('Success', implode('
', $messages)); return redirect()->refresh()->with(compact('success')); } diff --git a/src/Support/SessionMessage.php b/src/Support/SessionMessage.php new file mode 100644 index 000000000..86c23fed3 --- /dev/null +++ b/src/Support/SessionMessage.php @@ -0,0 +1,39 @@ +with() 序列化后变为数组的问题 + */ +class SessionMessage +{ + public function __construct( + protected string $title = '', + protected string $message = '', + protected array $options = [], + ) { + } + + public static function make(string $title, string $message = '', array $options = []): static + { + return new static($title, $message, $options); + } + + public function getTitle(): string + { + return $this->title; + } + + public function getMessage(): string + { + return $this->message; + } + + public function getOptions(): array + { + return $this->options; + } + +} diff --git a/src/Support/helpers.php b/src/Support/helpers.php index 15b686789..8c591fdba 100755 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -2,10 +2,9 @@ use Dcat\Admin\Admin; use Dcat\Admin\Support\Helper; +use Dcat\Admin\Support\SessionMessage; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Contracts\Support\Renderable; -use Illuminate\Http\Request; -use Illuminate\Support\MessageBag; use Symfony\Component\HttpFoundation\Response; if (! function_exists('admin_setting')) { @@ -298,7 +297,7 @@ function admin_base_path($path = '') if (! function_exists('admin_toastr')) { /** - * Flash a toastr message bag to session. + * Flash a toastr message to session. * * @param string $message * @param string $type @@ -306,7 +305,7 @@ function admin_base_path($path = '') */ function admin_toastr($message = '', $type = 'success', $options = []) { - $toastr = new MessageBag(get_defined_vars()); + $toastr = SessionMessage::make($type, $message, $options); session()->flash('dcat-admin-toastr', $toastr); } @@ -353,7 +352,7 @@ function admin_warning($title, $message = '') if (! function_exists('admin_info')) { /** - * Flash a message bag to session. + * Flash a message to session. * * @param string $title * @param string $message @@ -361,7 +360,7 @@ function admin_warning($title, $message = '') */ function admin_info($title, $message = '', $type = 'info') { - $message = new MessageBag(get_defined_vars()); + $message = SessionMessage::make($title, $message); session()->flash($type, $message); }