A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/sessions/ below:

HTTP Sessions - Laravel MongoDB

In this guide, you can learn how to set up HTTP sessions by using Laravel MongoDB. Sessions allow your application to store information about a user across multiple server requests. Your application stores this information in a specified location that it can access in future requests that the user makes.

Note Session Handler Implementation

The v5.4 Laravel MongoDB introduces the dedicated MongoDbSessionHandler class that extends the Laravel DatabaseSessionHandler class to store session information. The mongodb session driver saves user IDs, IP addresses, and user agents if present.

In v5.3 and earlier, the session driver uses the MongoDbSessionHandler class from the Symfony framework.

To learn more about support for sessions, see HTTP Session in the Laravel documentation.

Before you can register a session, you must configure your connection to MongoDB in your application's config/database.php file. To learn how to set up this connection, see the Configure Your MongoDB Connection step of the Quick Start guide.

Next, you can select the session driver and connection in one of the following ways:

  1. In an .env file, by setting the following environment variables:

    SESSION_DRIVER=mongodbSESSION_CONNECTION=mongodb
  2. In the config/session.php file, as shown in the following code:

    <?php return [    'driver' => 'mongodb',         'connection' => 'mongodb',     'table' => 'sessions',         'lifetime' => null,            'options' => []            ];

The following list describes other driver options that you can set in the options array:

We recommend that you create an index on the expiry_field field for garbage collection. You can also automatically expire sessions in the database by creating a TTL index on the collection that stores session information.

You can use the Schema builder to create a TTL index, as shown in the following code:

Schema::create('sessions', function (Blueprint $collection) {    $collection->expire('expires_at', 0);});

Setting the time value to 0 in the index definition instructs MongoDB to expire documents at the clock time specified in the expires_at field.

To learn more about using the Schema builder to create indexes, see the Create Sparse, TTL, and Unique Indexes section of the Schema Builder guide.

To learn more about TTL indexes, see Expire Data from Collections by Setting TTL in the Server manual.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4