Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Laravel-错误或无效输入字段上的消息Toastr_Javascript_Jquery_Laravel_Laravel 5_Eloquent - Fatal编程技术网

Javascript Laravel-错误或无效输入字段上的消息Toastr

Javascript Laravel-错误或无效输入字段上的消息Toastr,javascript,jquery,laravel,laravel-5,eloquent,Javascript,Jquery,Laravel,Laravel 5,Eloquent,我在添加、编辑和删除时收到此消息通知,但当字段中出现错误时(例如,我将文本框留空),则会弹出错误,但错误不是toast,而是一个div class=“alert alert danger>。您能帮我将其转换为toastr吗 下面是我在messages.blade.php @if(count($errors) > 0) @foreach($errors->all() as $error) <div class="alert alert-dange

我在添加、编辑和删除时收到此消息通知,但当字段中出现错误时(例如,我将文本框留空),则会弹出错误,但错误不是toast,而是一个
div class=“alert alert danger>
。您能帮我将其转换为toastr吗

下面是我在
messages.blade.php

@if(count($errors) > 0)
    @foreach($errors->all() as $error)
        <div class="alert alert-danger">
            {{$error}}
        </div>
     @endforeach
@endif
我的控制器:

以下是成功创建页面时返回视图的位置:

$notification = array(
    'message' => 'Employee Information Created!',
    'alert-type' => 'success'
);
    
return redirect('/admin/employeemaintenance/show')
            ->with( $notification, 'Employee Information Created');

如何解决这一问题?

如果您想要toast错误,我认为最简单的方法可能是将
警报危险
替换为toastr:

<script>
    @if(count($errors) > 0)
        @foreach($errors->all() as $error)
            toastr.error("{{ $error }}");
        @endforeach
    @endif
</script>

为了让
error
正常工作,你需要发送
'alert-type'=>'error'
你能给出代码吗?我的代码上有很多警报,我很困惑,请检查你的控制台,同时确保你确实有验证错误。好的,现在可以工作了,只是代码位置的改变;)Thanj没问题,很乐意帮助
<script>
    @if(count($errors) > 0)
        @foreach($errors->all() as $error)
            toastr.error("{{ $error }}");
        @endforeach
    @endif
</script>
toastr.options = {
    "preventDuplicates": true
}