Laravel redirect with data not working Laravel redirect with data not working laravel laravel

Laravel redirect with data not working


Since the with method flashes data to the session, you may retrieve the data using the typical Session::get method.

So you have to get as

$message = Session::get('message');


You can use this on your blade template:

@if( Session::has('message') )    <div class="alert alert-success alert-dismissable">        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>        {{ Session::get('message') }}    </div>@endif

Reference:easylaravelblog


You can check APP/kernel.php and look for this:

\Illuminate\Session\Middleware\StartSession::class,

Check if it is defined more than once like in this example:

protected $middleware = [\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,\Illuminate\Session\Middleware\StartSession::class,];protected $middlewareGroups = ['web' => [    \App\Http\Middleware\EncryptCookies::class,    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,    \Illuminate\Session\Middleware\StartSession::class,    \Illuminate\View\Middleware\ShareErrorsFromSession::class,    \App\Http\Middleware\VerifyCsrfToken::class,    \Illuminate\Routing\Middleware\SubstituteBindings::class,],

You can comment any one of the two or delete it. We need to define it one time only.