dimanche 20 novembre 2016

Laravel 5.3 session flash data not working at all

No flash data are available in case of-

1. Form validation
2. Redirect like redirect()->route('home')->with('msg','Some message')
2. Manually set flashdata using session()-> or Session:: 

Cases I have tested with help of artisan and web tool-

1. All the routes are under "web" middleware
2. No double redirection are happening
3. Auth is woking fine(login and user session)
4. Laravel version: 5.3.23

Snap of the Controller

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
//        $this->isAuthorized();
    }
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('home');
}
public function profile()
{
        return redirect()->route('home')->with('msg', "test message");
}

}

Snaps of Kernel.php

    protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \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,          
];

/**
 * The application's route middleware groups.
 *
 * @var array
 */
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,
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];

/**
 * The application's route middleware.
 *
 * These middleware may be assigned to groups or used individually.
 *
 * @var array
 */
protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];

var_dump of session() in blade file gives:

Array
(

[_token] => fru0pxo9Y4648p5ntJ1pOIY2mE6FCLlNPRY3RYAg
[url] => Array
    (
    )

[_previous] => Array
    (
        [url] => http://ift.tt/2fJpDEZ
    )

[_flash] => Array
    (
        [old] => Array
            (
            )

        [new] => Array
            (
            )

    )

[login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d] => 1
)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire