laravel redirect forget session ?

  • Working in the back area. Have a session created in Method A, now I want to access in the B method on the Session. The values are lost?
    Can someone help me please. Maybe it has to do with it I'm in the back area. The rights are set correctly.

    Thanks for the help, greetings

  • Global Moderator


    Hello dieter,

    The session should be accessible if you or your app has not dropped it before requesting it.
    Could you post a snippet on how are you setting session value and where are you doing it, then we can look at it.

  • Ok, thank you for your help.
    For information: The controller are in the admin area not in the public area

    * Store a newly created resource in storage.
    * C:\xampp\htdocs\xxx\Modules\Newsletter\Http\Controllers\Admin\InhaltController.php
    * redirect to method vorschau()
    * The Permission are set
    * The controller are in the admin area not in the public area
    public function store2(Request $request)

        $entitys = $request->input('de');
        foreach($entitys as $key => $entity){
            $content[$key] =  $entity;
        // session füllen
        // Session auslesen
        $content = Session::pull('newsletter.content');
        $content = (object) $content[0];
        flash()->success(trans('core::core.messages.resource created', ['name' => trans('newsletter::inhalts.title.inhalts')]));
        return redirect()->route('admin.newsletter.inhalt.vorschau');

    * View the data
    *from method store2

    public function vorschau(Request $request)
        echo 'bin in vorsschau';
        // Session read
        $user = Session::pull('newsletter.content');
       $user = (object) $user[0];


  • Global Moderator


    Okay this seems to be long-standing bug/problem/occurrence in Laravel itself, see here.
    Some people reporting that php artisan optimize --force fixed problem for them.

    What you could do and would probably work is to manually call Session::save(); after you are done with setting values.

  • Thanks for the help, but it was not.
    I think the fault lies in the admin or backend area.
    In the public area there is no problem. My controller is below the
    Folders 'admin' with auth protectet.
    Tried to google really been 3 hours. No idea why it
    in backend area will not do.

    How submitter the data 'without session' , with the 'method' => 'post' in my redirect. The 'method' => 'get' is false because I have a lot of data.
    If I in the backendRoutes.php the Method 'post' take, then i get a
    ERROR: MethodNotAllowedHttpException in RouteCollection.php line 219:

    this run is aber not good, too mutch data for the uri
    get('inhalts/vorschau', ['as' => 'admin.newsletter.inhalt.vorschau', 'uses' => 'InhaltController@vorschau']);

    but this is with error
    post('inhalts/vorschau', ['as' => 'admin.newsletter.inhalt.vorschau', 'uses' => 'InhaltController@vorschau']);

    My backendRoutes.php

    $router->group(['prefix' =>'/newsletter'], function (Router $router) {
    $router->bind('inhalts', function ($id) {
    return app('Modules\Newsletter\Repositories\InhaltRepository')->find($id);
    get('inhalts', ['as' => 'admin.newsletter.inhalt.index', 'uses' => 'InhaltController4']);
    post('inhalts/create', ['as' => 'admin.newsletter.inhalt.create', 'uses' => 'InhaltController@create']);
    post('inhalts/store2', ['as' => 'admin.newsletter.inhalt.store2', 'uses' => 'InhaltController@store2']);

    get('inhalts/vorschau', ['as' => 'admin.newsletter.inhalt.vorschau', 'uses' => 'InhaltController@vorschau']);
    post('inhalts', ['as' => '', 'uses' => 'InhaltController@store']);
    get('inhalts/{contacts}/edit', ['as' => 'admin.newsletter.inhalt.edit', 'uses' => 'InhaltController@edit']);
    put('inhalts/{contacts}/edit', ['as' => 'admin.newsletter.inhalt.update', 'uses' => 'InhaltController@update']);
    delete('inhalts/{contacts}', ['as' => 'admin.newsletter.inhalt.destroy', 'uses' => 'InhaltController@destroy']);


    thank you

  • Global Moderator


    This is definitely not because of your route or controller setup, this is tied to Laravel itself.

    Update: This is silly i didn't notice that you use PULL method of session which does Get the value of a given key and then forget it.
    So on your next request you have no key, because you pulled it out of session.
    So use Session::get('key') instead.

  • problem solved :))
    Thank you

Log in to reply

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.