Home  >  Q&A  >  body text

Session does not display correctly in Laravel 10 after AJAX request

<p>I am developing a web application using Laravel framework. I'm using the Laravel session system in part of my application and configured it to store sessions in a database. </p> <p>My problem is that the session set in one of the routes in the application does not display correctly in other pages and instead returns a null value. I should mention that this problem only occurs when I send a request to the server via AJAX and update the session. </p> <p>I have checked all session configuration settings as well as php.ini and .env settings, but the problem persists. Do you have any ideas to solve this problem? </p> <p>https://gist.github.com/realrezamirzaei/3fd51d57a95f90bacd3cc4aec06ba923</p> <p>"I'm trying to configure Laravel sessions to store sessions in the database, and I've checked the session settings in the php.ini and .env files. However, the session set in one of the routes in my application doesn't The display displays correctly in other pages, but a null value is returned. I want the session to display correctly on all pages."</p>
P粉295728625P粉295728625437 days ago497

reply all(1)I'll reply

  • P粉891237912

    P粉8912379122023-09-02 10:11:25

    I understand the problem I have a problem when I want to request from another domain to the main site. But I realized that this problem can be solved by using fruitcake/laravel-cors package, and considering that I am using Laravel version 10, there is no need to use this package, Adding it to the core files in the web and api sections is enough. Add this:

    \Illuminate\Http\Middleware\HandleCors::class

    reply
    0
  • Cancelreply