Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions resources/views/partials/alerts.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@if($error = session()->get('error'))
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> &nbsp;{{ \Illuminate\Support\Arr::get($error->get('title'), 0) }}</h4>
<p>{!! \Illuminate\Support\Arr::get($error->get('message'), 0) !!}</p>
<h4><i class="icon fa fa-ban"></i> &nbsp;{{ $error->getTitle() }}</h4>
<p>{!! $error->getMessage() !!}</p>
</div>
@elseif ($errors = session()->get('errors'))
@if ($errors->hasBag('error'))
Expand All @@ -19,23 +19,23 @@
@if($success = session()->get('success'))
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i> &nbsp;{{ \Illuminate\Support\Arr::get($success->get('title'), 0) }}</h4>
<p>{!! \Illuminate\Support\Arr::get($success->get('message'), 0) !!}</p>
<h4><i class="icon fa fa-check"></i> &nbsp;{{ $success->getTitle() }}</h4>
<p>{!! $success->getMessage() !!}</p>
</div>
@endif

@if($info = session()->get('info'))
<div class="alert alert-info alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-info"></i> &nbsp;{{ \Illuminate\Support\Arr::get($info->get('title'), 0) }}</h4>
<p>{!! \Illuminate\Support\Arr::get($info->get('message'), 0) !!}</p>
<h4><i class="icon fa fa-info"></i> &nbsp;{{ $info->getTitle() }}</h4>
<p>{!! $info->getMessage() !!}</p>
</div>
@endif

@if($warning = session()->get('warning'))
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-warning"></i> &nbsp;{{ \Illuminate\Support\Arr::get($warning->get('title'), 0) }}</h4>
<p>{!! \Illuminate\Support\Arr::get($warning->get('message'), 0) !!}</p>
<h4><i class="icon fa fa-warning"></i> &nbsp;{{ $warning->getTitle() }}</h4>
<p>{!! $warning->getMessage() !!}</p>
</div>
@endif
11 changes: 8 additions & 3 deletions resources/views/partials/exception.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
@if(isset($errors) && $errors->hasBag('exception'))
<?php $error = $errors->getBag('exception'); ?>
@php
$error = $errors->getBag('exception');
$errorType = $error->first('type');
$errorFile = $error->first('file');
$errorLine = $error->first('line');
@endphp
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4>
<i class="icon fa fa-warning"></i>
<i style="border-bottom: 1px dotted #fff;cursor: pointer;" title="{{ $error->get('type')[0] }}" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">{{ class_basename($error->get('type')[0]) }}</i>
In <i title="{{ $error->get('file')[0] }} line {{ $error->get('line')[0] }}" style="border-bottom: 1px dotted #fff;cursor: pointer;" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">{{ basename($error->get('file')[0]) }} line {{ $error->get('line')[0] }}</i> :
<i style="border-bottom: 1px dotted #fff;cursor: pointer;" title="{{ $errorType }}" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">{{ class_basename($errorType) }}</i>
In <i title="{{ $errorFile }} line {{ $errorLine }}" style="border-bottom: 1px dotted #fff;cursor: pointer;" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">{{ basename($errorFile) }} line {{ $errorLine }}</i> :
</h4>
<p><a style="cursor: pointer;" onclick="$('#dcat-admin-exception-trace').toggleClass('hidden');$('i', this).toggleClass('fa-angle-double-down fa-angle-double-up');"><i class="fa fa-angle-double-down"></i>&nbsp;&nbsp;{!! $error->first('message') !!}</a></p>

Expand Down
6 changes: 3 additions & 3 deletions resources/views/partials/toastr.blade.php
Original file line number Diff line number Diff line change
@@ -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
<script>$(function () { toastr.{{$type}}('{!! $message !!}', null, {!! $options !!}); })</script>
@endif
12 changes: 3 additions & 9 deletions src/Http/Controllers/ScaffoldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
}
Expand All @@ -293,10 +290,7 @@ protected function backWithSuccess($paths, $message)

$messages[] = "<br />$message";

$success = new MessageBag([
'title' => 'Success',
'message' => implode('<br />', $messages),
]);
$success = SessionMessage::make('Success', implode('<br />', $messages));

return redirect()->refresh()->with(compact('success'));
}
Expand Down
39 changes: 39 additions & 0 deletions src/Support/SessionMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Dcat\Admin\Support;

/**
* Session 消息对象(兼容 Laravel 10-13).
*
* 解决 Laravel 13 中 MessageBag 通过 redirect()->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);

Check failure on line 21 in src/Support/SessionMessage.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Unsafe usage of new static().

Check failure on line 21 in src/Support/SessionMessage.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Unsafe usage of new static().

Check failure on line 21 in src/Support/SessionMessage.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Unsafe usage of new static().

Check failure on line 21 in src/Support/SessionMessage.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Unsafe usage of new static().

Check failure on line 21 in src/Support/SessionMessage.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Unsafe usage of new static().
}

public function getTitle(): string
{
return $this->title;
}

public function getMessage(): string
{
return $this->message;
}

public function getOptions(): array
{
return $this->options;
}

}
11 changes: 5 additions & 6 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -298,15 +297,15 @@

if (! function_exists('admin_toastr')) {
/**
* Flash a toastr message bag to session.
* Flash a toastr message to session.
*
* @param string $message
* @param string $type
* @param array $options
*/
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);
}
Expand Down Expand Up @@ -353,15 +352,15 @@

if (! function_exists('admin_info')) {
/**
* Flash a message bag to session.
* Flash a message to session.
*
* @param string $title
* @param string $message
* @param string $type
*/
function admin_info($title, $message = '', $type = 'info')
{
$message = new MessageBag(get_defined_vars());
$message = SessionMessage::make($title, $message);

session()->flash($type, $message);
}
Expand Down Expand Up @@ -566,7 +565,7 @@
* @param Request|null $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector
*/
function admin_redirect($to, int $statusCode = 302, ?Request $request = null)

Check failure on line 568 in src/Support/helpers.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Parameter $request of function admin_redirect() has invalid type Request.

Check failure on line 568 in src/Support/helpers.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Parameter $request of function admin_redirect() has invalid type Request.

Check failure on line 568 in src/Support/helpers.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Parameter $request of function admin_redirect() has invalid type Request.

Check failure on line 568 in src/Support/helpers.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Parameter $request of function admin_redirect() has invalid type Request.

Check failure on line 568 in src/Support/helpers.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Parameter $request of function admin_redirect() has invalid type Request.
{
return Helper::redirect($to, $statusCode, $request);
}
Expand Down
Loading