lundi 21 septembre 2015

Flash data in Laravel 5

I'm trying to display flash data but it's not showing properly. It's showing:

{{ Session::get('flash_message') }}

but it should be the message

"Your article has been created"

What's wrong with my code? Thanks!

In my controller I have:

public function store(ArticleRequest $request) 
{ 
    Auth::user()->articles()->create($request->all());

    \Session::flash('flash_message', 'Your article has been created');

    return redirect('articles');            
}

My app.blade.php is:

<!DOCTYPE html>
    <head>
    <meta charset="UTF-8">
        <title>App Name - @yield('title')</title>
        <link rel="stylesheet" href="http://ift.tt/1K1B2rp">
        <link rel="stylesheet" href="{{ elixir('css/all.css') }}">
        <script src= "http://ift.tt/1EbO5VO"></script>
        <script src="js/app.js"></script>
    </head>
    <body>

        <div class="container">

            @if(Session::has('flash_message'))
                <div class="alert alert-success">{{ Session::get('flash_message') }}</div>
            @endif

            @yield('content')

        </div>

        @yield('footer')

    </body>
</html>

In my route.php I have the following: Curly braces display content as string not variables.

<?php
Blade::setContentTags('<%', '%>'); // for variables and all things Blade
Blade::setEscapedContentTags('<%%', '%%>'); // for escaped data

Route::get('/', function() {
        return 'Home Page';
});

Route::get('blade', function () {
    return view('about');
});

   
Route::get('about', 'HelloWorld@about');

Route::get('foo', ['middleware' => 'manager', function() {
        return 'this page may only be viewed by managers';
}]);
   

Route:resource('articles', 'ArticlesController');

Route::controllers([
        'auth' => 'Auth\AuthController',
        'password' => 'Auth\PasswordController'

]);


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire