1
votes

This is the array I am getting when using dd(session()).

SessionManager {#551 ▼
  #app: Application {#5 ▶}
  #customCreators: []
  #drivers: array:1 [▼
    "file" => Store {#553 ▼
      #id: "Kg81ge6ve7bPg4Vos5qsKqvU3Bmo2k6U0hQncxY1"
      #name: "project_session"
      #attributes: array:1 [▶]
      #handler: FileSessionHandler {#552 ▶}
      #started: false
    }
  ]
}

It is working fine with auth middleware.

SessionManager {#739 ▼
  #app: Application {#5 ▶}
  #customCreators: []
  #drivers: array:1 [▼
    "file" => Store {#742 ▼
      #id: "3nTG8ApjScmeivyKtwDw1nsfOQ9hK8lrwkbLJfTa"
      #name: "project_session"
      #attributes: array:5 [▶]
      #handler: FileSessionHandler {#741 ▶}
      #started: true
    }
  ]
}

I am building website with customer login. I am trying to access currency through session it is setting when user is logged in. But when I try to set it in the session then it is not setting. When I looked into the session folder there is new file for every new request.

Hope somebody have gone through this. Because I have searched a lot and I didn't find anything. Thanks in advance.

Here is my kernel.php

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\TrustProxies::class,
    ];

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

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


    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,
    ];
}

Here is my routes.php

<?php
Route::group(['middleware' => ['web']], function(){
    Route::get('/', 'Front\HomeController@index');
    Route::get('/blog','Front\BlogController@index');
    Route::get('/blog/{slug}','Front\BlogController@show');
    Route::get('/{slug}','Front\PageController@show');
});

//Routes For Customer panel
Auth::routes();

Route::get('/customer/home', 'Customer\HomeController@index')->name('home');

Route::group( ['middleware' => ['auth'], 'prefix' => 'customer'], function(){
    Route::resource('products','Customer\ProductController');
    Route::resource('categories','Customer\CategoryController');
    Route::resource('posts','Customer\PostController');
    Route::resource('pages','Customer\PageController');
    Route::resource('packages','Customer\PackageController');
    Route::resource('clients','Customer\ClientController');
    Route::resource('faqs','Customer\FaqController');
    Route::resource('testimonials','Customer\TestimonialController');
    Route::resource('blogs','Customer\BlogController');
    Route::resource('currencies','Customer\CurrencyController');
});

I tried to remove web middleware from routes as someone suggested that web middleware is automatically set for routes. so if you add web middleware then you can get routes as 'web, web' middleware but when i get routes using php artisan route:list it gives me only web middleware.

I don't know how the session start works is there any method i can add to somewhere so i can start the session.

1
is \Illuminate\Session\Middleware\StartSession::class included in your web middleware group?CUGreen
yes, it is included.Sushil More

1 Answers

1
votes

because your session middlewares inserted into web group middleware, so that's run just in web group middleware. you should replace them and insert into middleware like this:

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
    \App\Http\Middleware\TrimStrings::class,
    \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    \App\Http\Middleware\TrustProxies::class,
    **\Illuminate\Session\Middleware\StartSession::class,// insert here 
    \Illuminate\View\Middleware\ShareErrorsFromSession::class // insert here**
];

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        **\Illuminate\Session\Middleware\StartSession::class,// remove this**
        // \Illuminate\Session\Middleware\AuthenticateSession::class,
        **\Illuminate\View\Middleware\ShareErrorsFromSession::class // remove this**
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

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


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,
];