1

After the upgrade from Laravel 5.2 to 5.3 I'm not able the add the Flash message.

This is the code we use:

return redirect()->back()->with('alert-success', 'My Message');

And for displaying the message:

@foreach (['danger', 'warning', 'success', 'info'] as $msg)
    @if(Session::has('alert-' . $msg))
        <div class="alert alert-{{ $msg }} alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            {{ Session::get('alert-' . $msg) }}
        </div>
    @endif
@endforeach

We also cannot use the login messages if we provider wrong credentials:

<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
    {{ csrf_field() }}
    <div class="form-group has-feedback {{ $errors->has('email') ? ' has-error' : '' }}">
        <input type="email" name="email" class="form-control" placeholder="Email" value="{{ old('email') }}">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        @if ($errors->has('email'))
            <span class="help-block">
                <strong>{{ $errors->first('email') }}</strong>
            </span>
        @endif
    </div>
    <div class="form-group has-feedback {{ $errors->has('password') ? ' has-error' : '' }}">
        <input type="password" name="password" class="form-control" placeholder="Password">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        @if ($errors->has('password'))
            <span class="help-block">
                <strong>{{ $errors->first('password') }}</strong>
            </span>
        @endif
    </div>
    <div class="row">
        <!-- /.col -->
        <div class="col-xs-12">
            <button type="submit" class="btn btn-primary btn-block btn-flat">
                Login
            </button>
        </div>
    </div>
</form>
Robin Dirksen
  • 3,322
  • 25
  • 40

2 Answers2

1

If you used 5.2.27 or lower and moved to 5.3, most definitely you've used web middleware in routes file. You need to move web middleware from Laravel 5.3 routes to make sessions work, because since 5.2.27 if you're trying to add it manually to web.php, it brakes sessions related functionality.

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • Do not return `web` middleware to `web.php`, keep it removed. Try to [clear all Laravel cache](http://stackoverflow.com/questions/37259103/laravel-application-is-not-working-after-uploading-to-the-server/37259162#37259162). Also, check `app\Http\Kernel.php`. In 5.3 and latest 5.2.x in it's different. [Here's](https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php) how it looks like in 5.3. – Alexey Mezenin Jan 05 '17 at 09:38
0

The solution can with an edit in the Kernel.php.

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,

    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
];

When I added the StartSession and ShareErrorsFromSession it worked as the old site would.

Robin Dirksen
  • 3,322
  • 25
  • 40