如何将数组传递给flash消息?

时间:2016-12-29 15:21:04

标签: laravel laravel-5 laravel-5.2

我想将它们存在的additional_feature数组发送到flash消息。现在我只发送一个additional_feature。任何建议我怎么能这样做?

{{1}}

3 个答案:

答案 0 :(得分:1)

您可以使用session()代替with()

session->flash('someVar', $someArray);

您可以尝试的另一件事是对数组进行串行化并将其作为字符串传递。然后取消它并使用。

此外,您可以使用简单的会话保存数组:

session(['someVar' => $someArray]);

然后获取并手动删除:

session('somevar');
session()->forget('someVar');

答案 1 :(得分:1)

我们遇到了同样的问题并分叉了包裹。你可以在这里找到它:

Forked at first from Laracasts/Flash to use multiple message

@if (Session::has('flash_notification.message'))
@if (Session::has('flash_notification.overlay'))
    @include('flash::modal', ['modalClass' => 'flash-modal', 'title' => Session::get('flash_notification.title'), 'body' => Session::get('flash_notification.message')])
@else
    <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
@endif

包含flash :: modal

的内容
@if (Session::has('flash_notification.messages'))
@foreach (Session::get('flash_notification.messages') as $flashMessage)
    @foreach($flashMessage as $type => $message)
        <script>
            $(function() {
                var message = ('{{ $message }}<br>').replace(/'/g, "&#8217;");
                customFlashMessage({
                    type: "{{ $type }}",
                    message: message
                });
            });
        </script>
    @endforeach
@endforeach
@endif

答案 2 :(得分:0)

return redirect()->back()->with(['session1' => $value, 'session2' => $value]);

在刀片模板中:

{{ Session::get('session1') }}
{{ Session::get('session2') }}