Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.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 Toastr将Laravel会话变量用作警报消息_Javascript_Twitter Bootstrap_Laravel_Laravel 5_Toastr - Fatal编程技术网

Javascript Toastr将Laravel会话变量用作警报消息

Javascript Toastr将Laravel会话变量用作警报消息,javascript,twitter-bootstrap,laravel,laravel-5,toastr,Javascript,Twitter Bootstrap,Laravel,Laravel 5,Toastr,我想从Bootstrap警报切换到Toastr警报。我目前的工作设置是: @if (Session::has('flash_notification.message')) <div class="alert alert-{{ Session::get('flash_notification.level') }}"> <button type="button" class="close" data-dismiss="alert"

我想从
Bootstrap
警报切换到
Toastr
警报。我目前的工作设置是:

@if (Session::has('flash_notification.message'))

     <div class="alert alert-{{ Session::get('flash_notification.level') }}">
         <button type="button" class="close" data-dismiss="alert" 
             aria-hidden="true">&times;</button>
         {{ Session::get('flash_notification.message') }}
     </div>

 @endif
但是,我想使用Laravel的会话变量来包含不同的消息和警告框:

@if (Session::has('flash_notification.message'))

    <script>
        $(document).ready(function() {

            toastr.options.timeOut = 4000;
            toastr.{{ Session::get('flash_notification.level') }}('{{ Session::get('flash_notification.message) }}');

        });
    </script>

@endif
@if(会话::has('flash_notification.message'))
$(文档).ready(函数(){
toastr.options.timeOut=4000;
toastr.{{Session::get('flash_notification.level')}}({{Session::get('flash_notification.message)}}});
});
@恩迪夫

我遇到了各种各样的错误,比如
意想不到的错误。任何帮助都将不胜感激。非常感谢。

由于您使用的是刀片模板,因此可以使用
{{var/function()}
输出变量/函数的内容。如果您想要未扫描的输出,可以使用
{!!var/function()!!}

因此,您的问题的解决方案是,您需要用
{{}
标记包围php代码:

@if (Session::has('flash_notification.message'))

    <script>
        $(document).ready(function() {

        toastr.{{ Session::get('flash_notification.level') }}
        ('{{ Session::get('flash_notification.message') }}');

        });
    </script>

@endif
@if(会话::has('flash_notification.message'))
$(文档).ready(函数(){
toastr.{{Session::get('flash_notification.level')}
({{Session::get('flash_notification.message')}});
});
@恩迪夫

谢谢您的回复。不幸的是,它返回的错误
出乎意料因为它在我的template.blade.php中,所以错误消息非常糟糕-
97A837778D68883DB99BFDF8C10C794第66行中的FatalErrorException:语法错误,意外“;”。第66行是:
toastr.{{Session::get('flash_notification.level')}}({{Session::get('flash_notification.message)}})
Session::get('flash\u notification.message)
-您缺少
flash\u notification.message之后的第二个
。非常正确!我自己也注意到了,谢谢。我现在就去检查一下。它看起来都是正确的,但是现在错误是:
uncaughtreferenceerror:$未定义
。jQuery在页脚中被调用,但是
document.ready
应该停止此错误吗?
@if (Session::has('flash_notification.message'))

    <script>
        $(document).ready(function() {

        toastr.{{ Session::get('flash_notification.level') }}
        ('{{ Session::get('flash_notification.message') }}');

        });
    </script>

@endif