简体   繁体   中英

Laravel Session data different in views and controllers

In my PagesController I have method view(Page $page) , which gets called by the route:

Route::get('{page}', 'PagesController@view');

The method body is as follows:

public function view(Page $page)
{

    // Process content vars
    $page->content = ContentVarsProcessor::process($page->content);

    var_dump(\Session::get('form_contact-form_response'));

    return $page->out();
}

And the $page->out() body is:

public function out()
{

    // ... some processing

    $content = view($view, $data)->render();

    return $content;
}

Inside the view, I have

{{ var_dump(session('form_'.$form->identifier.'_response')) }}

And the interest thing is that the two dumps show different data.. The data is flashed on form validation, and should be gone after 1 request, but it keeps persisting, while in the controller it's showing null. The dumps are as follows:

C:\wamp\www\wsv\app\Modules\Pages\Controllers\PagesController.php:21:null

C:\wamp\www\wsv\storage\framework\views\7dbbca5089cdc8f8c9e49cadafb0bb435b7adf4d.php:7:string '{"status":"error","errors":["Name is required"]}' (length=48)

On the same page, on the same request. What am I missing here?

Thanks

Same bug as per the other issue - inconsistent middleware included.

Laravel Flash Data Persisting indefinitely

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM