本文介绍了Laravel 8:如何使用Sweet Alert消息进行表单错误报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录刀片,其中包含一个表格:

I have a login blade which contains a form:

       <form method="POST" action="{{ route('login') }}">
            @csrf
            <div class="field">
                <span class="fas fa-user"></span>
                <input type="email" name="email" required>
                <label style="right:0;" class="BFarnaz">Email</label>
                @error('email')
                    alert()->success('{{ $message }}','message')->persistent('Ok');
                @enderror
            </div>
            <div class="field">
                <span class="fas fa-lock"></span>
                <input type="password">
                <label style="right:0;" class="BFarnaz">Password</label>
                @error('password')
                    alert()->success('{{ $message }}','message')->persistent('Ok');
                @enderror
            </div>
            <button class="BJadidBold">Login</button>
        </form>

我还成功安装了 Sweet Alert软件包,现在我想将其用于向用户显示表单错误:

I have also installed the Sweet Alert package successfully and now I want to use it for showing errors of forms to user:

@error('password')
    alert()->success('{{ $message }}','message')->persistent('Ok');
@enderror

但是这种方法是错误的,不幸的是,我不知道这样做的正确方法是什么...

But this way is wrong, and unfortunately I don't know what is the correct way of doing this...

所以,如果您知道正确的方法,请帮帮我.

So if you know the proper way, please help me out.

谢谢.

推荐答案

我使用了不同的软件包, realrashid/sweet-alert ,因为它使用SweetAlert2而不是SweetAlert.不要忘记已经包含了jquery.

I use a different package, realrashid/sweet-alert since it uses SweetAlert2 and not SweetAlert. Don't forget to have jquery already included.

安装后不要忘记发布资产:

After install don't forget to publish the assets:

php artisan sweetalert:publish

在主布局刀片中:

@include('sweetalert::alert')

控制器中的示例:

use RealRashid\SweetAlert\Facades\Alert;
//etc

public function sendEmail(SubmitContactForm $request)
    {
        // etc
        Alert::success('Email Sent', 'We have received your message and would like to thank you for writing to us.');
        return redirect()->back();
    }

这篇关于Laravel 8:如何使用Sweet Alert消息进行表单错误报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 09:13
查看更多