在RegisterController上,我添加以下代码:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath())->with('success', 'Registration Success');
}
在即时消息中,我添加了此:
@if ($message = Session::get('success'))
<script type="text/javascript">
Swal.fire({
icon: 'success',
title: 'Success!',
text: '{{ $message }}',
timer: 5000,
})
</script>
@endif
在app.scss,我添加了此
@import '~sweetalert2/dist/sweetalert2.css';
在app.js,我添加了此
window.Swal = require('sweetalert2/dist/sweetalert2.all');
然后我跑步
npm run prod
我尝试注册,没有SweetAlert2消息出现。
我尝试使用以下代码创建按钮:
<button class="btn btn-info" onclick="Swal.fire({
icon: 'success',
title: 'Success!',
text: 'Great, it Works',
timer: 5000,
})">TEST
</button>
它显示Sweetalert2消息。
有人可以帮我吗?
谢谢。
我已经找到了下面的代码解决方案,它可以工作。谢谢
@if ($message = Session::get('success'))
<script type="text/javascript">
function showMessage() {
Swal.fire({
icon: 'success',
title: 'Success!',
text: '{{ $message }}',
timer: 5000,
})
}
window.onload = showMessage;
</script>
@endif