Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning laravel 5 flash data in view page

Tags:

php

laravel-5

I did in controller

Session::flash('message', 'Successfully updated!');

and in view

@if (Session::has('message'))
                            <li>{!! Session::get('message') !!}</li>
                            @endif

However, nothing is passed on view, when i do var_dump(Session::get('message')); I can view message, pls help me

like image 836
ktm Avatar asked Jan 19 '15 06:01

ktm


2 Answers

It should be: with "\" in your controller

\Session::flash('message', 'Successfully updated!');

And in your view use session() as in Laravel docs.

    @if (Session::has('message'))
        <li>{!! session('message') !!}</li>
   @endif

Please see to official Laravel docs Or This very simple step by step tutorial Flash Messages in Laravel 5

like image 161
Ikong Avatar answered Sep 24 '22 02:09

Ikong


Assuming that in controller... in the method index() before returning the view you might have put that code Session::flash('message', 'Successfully updated!');

But the Session class here might be taken from the namespaces used in your controller. So add a "\" before session to make it work..

Like :

\Session::flash('message', 'Successfully updated!');
like image 20
Jeevan Prakash Avatar answered Sep 25 '22 02:09

Jeevan Prakash