title
Laravel 5.2 PHP - Build a Shopping Cart - #8 Cart Model & Session Storage

description
Tutorial on how to build a Shopping Cart using the Laravel PHP Framework (5.2). Source Code on Github: https://github.com/mschwarzmueller/laravel-shopping-cart-tutorial Want more Laravel? Check out my Udemy course on it: https://www.udemy.com/modern-web-development-with-laravel/?couponCode=YOUTUBE1 (Coupon: YOUTUBE1) You can follow me on Twitter (@maxedapps), Facebook (https://www.facebook.com/academindchannel/) or visit our Website (https://www.academind.com).

detail
{'title': 'Laravel 5.2 PHP - Build a Shopping Cart - #8 Cart Model & Session Storage', 'heatmap': [{'end': 1148.361, 'start': 1114.049, 'weight': 0.903}], 'summary': 'Tutorial series covers configuring laravel session, implementing session-based shopping cart, managing cart items using eloquent, and implementing session handling in laravel to create a functional shopping cart view.', 'chapters': [{'end': 194.88, 'segs': [{'end': 34.771, 'src': 'embed', 'start': 1.186, 'weight': 0, 'content': [{'end': 2.227, 'text': 'Welcome back, everyone.', 'start': 1.186, 'duration': 1.041}, {'end': 4.048, 'text': 'So this is where we finished.', 'start': 2.707, 'duration': 1.341}, {'end': 8.111, 'text': 'We have our product view here.', 'start': 4.168, 'duration': 3.943}, {'end': 10.833, 'text': "We were able to sign up, sign in, and that's all great.", 'start': 8.17, 'duration': 2.663}, {'end': 15.076, 'text': 'The first thing I want to do is I want to correct a little mistake I made.', 'start': 11.133, 'duration': 3.943}, {'end': 21.781, 'text': 'In the migrations here in the user table, I set the user table name to be user.', 'start': 15.916, 'duration': 5.865}, {'end': 24.362, 'text': 'It should be users there with an S at the end.', 'start': 21.821, 'duration': 2.541}, {'end': 25.203, 'text': "That's important.", 'start': 24.403, 'duration': 0.8}, {'end': 28.225, 'text': "Also, we'll need something else here.", 'start': 26.024, 'duration': 2.201}, {'end': 34.771, 'text': "We'll need the remember token, otherwise we'll get errors.", 'start': 28.285, 'duration': 6.486}], 'summary': 'Corrected migration mistake for user table, added remember token to prevent errors', 'duration': 33.585, 'max_score': 1.186, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M1186.jpg'}, {'end': 108.803, 'src': 'embed', 'start': 80.195, 'weight': 1, 'content': [{'end': 85.661, 'text': 'I will store everything in the session, so I will store my shopping cart in a session.', 'start': 80.195, 'duration': 5.466}, {'end': 94.109, 'text': "This has the advantage that it persists if the user navigates around, if the user leaves the page as long as the session hasn't expired yet,", 'start': 86.381, 'duration': 7.728}, {'end': 101.797, 'text': 'and also it has the advantage of allowing anonymous users to browse our items and create a shopping cart.', 'start': 94.89, 'duration': 6.907}, {'end': 108.803, 'text': "That's of course something other approaches where we would store our cart in the database would not be able to handle that greatly.", 'start': 102.037, 'duration': 6.766}], 'summary': 'Storing shopping cart in session allows persistence and anonymous browsing.', 'duration': 28.608, 'max_score': 80.195, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M80195.jpg'}, {'end': 194.88, 'src': 'embed', 'start': 127.133, 'weight': 3, 'content': [{'end': 130.395, 'text': 'So in here, you can set the default session driver.', 'start': 127.133, 'duration': 3.262}, {'end': 134.076, 'text': 'And this is pointing to the environment file, this .', 'start': 130.794, 'duration': 3.282}, {'end': 134.837, 'text': 'env file.', 'start': 134.076, 'duration': 0.761}, {'end': 136.297, 'text': 'And in this .', 'start': 135.517, 'duration': 0.78}, {'end': 141.5, 'text': 'env file, you can set up your session driver, which by default is file,', 'start': 136.297, 'duration': 5.203}, {'end': 150.264, 'text': 'which means that Laravel will create a file in the storage app excuse me storage framework folder and then here at sessions.', 'start': 141.5, 'duration': 8.764}, {'end': 154.246, 'text': 'You see, I already got some files from testing here, but I can get rid of those.', 'start': 150.524, 'duration': 3.722}, {'end': 158.81, 'text': 'and these are the files where Laravel will store your session.', 'start': 155.326, 'duration': 3.484}, {'end': 167.499, 'text': 'Now Laravel has different session storages and you can learn more by simply googling for Laravel session and then checking out their docs.', 'start': 159.41, 'duration': 8.089}, {'end': 177.749, 'text': "Just make sure to check them out for the latest version 5.2 for example and here you'll see how to configure it and how to store it.", 'start': 168.38, 'duration': 9.369}, {'end': 180.831, 'text': "So that's something you might have a look at.", 'start': 178.77, 'duration': 2.061}, {'end': 191.018, 'text': "You'll also learn that in this sessions.php file in the config folder, you can set how long a session should be alive in minutes here and so on.", 'start': 181.192, 'duration': 9.826}, {'end': 194.88, 'text': 'So that is some important configuration stuff you should be aware of.', 'start': 191.318, 'duration': 3.562}], 'summary': 'Configure session driver in laravel, with default as file storage and options for different session storages.', 'duration': 67.747, 'max_score': 127.133, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M127133.jpg'}], 'start': 1.186, 'title': 'Configuring laravel session and implementing session-based shopping cart', 'summary': "Discusses fixing the user table name to 'users' in laravel migrations, configuring the default session driver, exploring different session storage options, and implementing a session-based shopping cart to allow anonymous users to browse and create a shopping cart, with the advantage of persisting user data even if the session hasn't expired yet.", 'chapters': [{'end': 125.651, 'start': 1.186, 'title': 'Fixing user table name and implementing session-based shopping cart', 'summary': "Discusses fixing the user table name to 'users' in laravel migrations and implementing a session-based shopping cart to allow anonymous users to browse and create a shopping cart, with the advantage of persisting user data even if the session hasn't expired yet.", 'duration': 124.465, 'highlights': ["The user table name in the migrations should be corrected from 'user' to 'users' to avoid errors and ensure proper functionality.", "To reset and rerun the migrations in Laravel, the command 'php artisan migrate reset' should be executed in the terminal, followed by 'php artisan migrate' and 'php artisan db:seed' to reseed the database.", "Implementing a session-based shopping cart in Laravel allows for persisting user data even if the session hasn't expired yet and enables anonymous users to browse and create a shopping cart.", "Storing the shopping cart in a session in Laravel has the advantage of persisting user data even if the session hasn't expired yet, and allowing anonymous users to browse and create a shopping cart."]}, {'end': 194.88, 'start': 127.133, 'title': 'Configuring laravel session', 'summary': 'Provides an overview of configuring the default session driver in laravel, including setting up session storage in the .env file, exploring different session storage options, and configuring session duration in the sessions.php file.', 'duration': 67.747, 'highlights': ['You can set the default session driver in the .env file, with the default being file storage, creating session files in the storage/app/framework/sessions folder.', 'Laravel offers different session storage options, which can be explored further by referring to the official documentation for the latest version.', 'In the sessions.php file, located in the config folder, you can configure the duration of a session in minutes and other important configuration settings.']}], 'duration': 193.694, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M1186.jpg', 'highlights': ["The user table name in the migrations should be corrected from 'user' to 'users' to avoid errors and ensure proper functionality.", "Implementing a session-based shopping cart in Laravel allows for persisting user data even if the session hasn't expired yet and enables anonymous users to browse and create a shopping cart.", "Storing the shopping cart in a session in Laravel has the advantage of persisting user data even if the session hasn't expired yet, and allowing anonymous users to browse and create a shopping cart.", 'You can set the default session driver in the .env file, with the default being file storage, creating session files in the storage/app/framework/sessions folder.', 'Laravel offers different session storage options, which can be explored further by referring to the official documentation for the latest version.', 'In the sessions.php file, located in the config folder, you can configure the duration of a session in minutes and other important configuration settings.']}, {'end': 940.396, 'segs': [{'end': 275.685, 'src': 'embed', 'start': 222.792, 'weight': 3, 'content': [{'end': 230.94, 'text': 'however, it is important to note that this should take a parameter id, because i need to know which item to add to my cart right.', 'start': 222.792, 'duration': 8.148}, {'end': 240.279, 'text': "then i'll configure this route to use my product controller, product controller here.", 'start': 230.94, 'duration': 9.339}, {'end': 248.147, 'text': 'And of course, get add to cart could be a good name for this action in the controller, so for the function handling this.', 'start': 241.3, 'duration': 6.847}, {'end': 250.689, 'text': "And I'll give this route a name as well.", 'start': 248.747, 'duration': 1.942}, {'end': 255.474, 'text': 'And the name I want to give it here is product add to cart.', 'start': 251.57, 'duration': 3.904}, {'end': 259.618, 'text': 'of course choose whatever works for you here.', 'start': 256.437, 'duration': 3.181}, {'end': 263.8, 'text': "so next in the product controller i'll add this function.", 'start': 259.618, 'duration': 4.182}, {'end': 266.421, 'text': "so i'll add my public function.", 'start': 263.8, 'duration': 2.621}, {'end': 274.105, 'text': "get add to cart, and i know that this will get the id of the product, but i'll also need access to my requests.", 'start': 266.421, 'duration': 7.684}, {'end': 275.685, 'text': 'instead will store my session.', 'start': 274.105, 'duration': 1.58}], 'summary': 'Configuring route for adding item to cart using product controller.', 'duration': 52.893, 'max_score': 222.792, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M222792.jpg'}, {'end': 355.643, 'src': 'embed', 'start': 324.801, 'weight': 0, 'content': [{'end': 327.242, 'text': 'I want to have, oh, and here a T is missing.', 'start': 324.801, 'duration': 2.441}, {'end': 332.244, 'text': 'I want to have a real cart object in my session.', 'start': 327.902, 'duration': 4.342}, {'end': 341.167, 'text': "So I'm going to create a new model in my app folder here or in this, yeah, in the app folder where I have my product and user model as well.", 'start': 332.724, 'duration': 8.443}, {'end': 344.908, 'text': "Now, I'm going to create this by hand and I'll name it cart.php.", 'start': 341.867, 'duration': 3.041}, {'end': 348.379, 'text': "Now this won't be using Eloquent.", 'start': 346.158, 'duration': 2.221}, {'end': 355.643, 'text': "I'm still copying this just to, well, have a little bit less to type, but I won't be extending model.", 'start': 349.159, 'duration': 6.484}], 'summary': 'Creating a new cart object in the app folder named cart.php, not using eloquent.', 'duration': 30.842, 'max_score': 324.801, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M324801.jpg'}, {'end': 465.645, 'src': 'embed', 'start': 442.02, 'weight': 5, 'content': [{'end': 451.763, 'text': 'Now the important thing about this card is I will recreate it each time I access it basically whenever I add a new item or whenever I get the items.', 'start': 442.02, 'duration': 9.743}, {'end': 458.505, 'text': 'Now for that of course I need to pass the old card to it and then recreate the card based on that old card.', 'start': 452.303, 'duration': 6.202}, {'end': 465.645, 'text': "I'm following this approach to always have the correct state of this card.", 'start': 459.537, 'duration': 6.108}], 'summary': "Recreating the card each time it's accessed to maintain correct state.", 'duration': 23.625, 'max_score': 442.02, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M442020.jpg'}, {'end': 911.738, 'src': 'embed', 'start': 858.356, 'weight': 1, 'content': [{'end': 863.978, 'text': "I don't just want to do nothing, I want to increase the quantity and I also want to change the price of course.", 'start': 858.356, 'duration': 5.622}, {'end': 866.399, 'text': "So I'll do that if I could type here.", 'start': 864.438, 'duration': 1.961}, {'end': 875.923, 'text': 'So price should be the item price times the stored item quantity.', 'start': 867.199, 'duration': 8.724}, {'end': 887.84, 'text': 'So item price is just the price of a single item, and stored item quantity is simply how many of such products do we have in the cart yet.', 'start': 877.116, 'duration': 10.724}, {'end': 896.063, 'text': "So let's say we have three times Harry Potter, then this would be three and since Harry Potter costs 10, this would be 10,", 'start': 888.24, 'duration': 7.823}, {'end': 898.945, 'text': 'and we would set the stored item price to 30..', 'start': 896.063, 'duration': 2.882}, {'end': 902.146, 'text': 'And again, stored item is kind of the group of those items.', 'start': 898.945, 'duration': 3.201}, {'end': 906.737, 'text': "Then as explained, I'm adding this to my array here.", 'start': 903.956, 'duration': 2.781}, {'end': 911.738, 'text': 'And of course, I also need to update the total quantity and price of my card.', 'start': 907.537, 'duration': 4.201}], 'summary': 'Increase quantity and change price based on item quantity and price. update total quantity and price of cart.', 'duration': 53.382, 'max_score': 858.356, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M858356.jpg'}], 'start': 195.52, 'title': 'Cart management in laravel', 'summary': 'Discusses adding items to a cart in laravel using eloquent to fetch products by id and creating a custom cart object in the session. it also covers shopping cart management, including grouping items, updating total quantity and price, and recreating the cart upon each access.', 'chapters': [{'end': 380.016, 'start': 195.52, 'title': 'Adding items to cart in laravel', 'summary': 'Discusses setting up a route and controller in laravel to add items to a cart, utilizing eloquent to fetch products by id and creating a custom cart object in the session to store individual products.', 'duration': 184.496, 'highlights': ["Setting up a new route 'add to cart' in the routes file and configuring it to take a parameter ID for adding items to the cart.", "Creating a function 'get add to cart' in the product controller to handle adding items to the cart and fetching the product using Eloquent by ID.", "Creating a custom cart object named 'cart.php' in the app folder to store individual products, not just an array of items."]}, {'end': 940.396, 'start': 380.357, 'title': 'Shopping cart management', 'summary': 'Discusses the creation of a shopping cart management system, emphasizing the grouping of items, updating total quantity and price, and the use of constructor function to ensure the correct state of the card, with an emphasis on the need to recreate it upon each access.', 'duration': 560.039, 'highlights': ['The chapter discusses the creation of a shopping cart management system, emphasizing the grouping of items, updating total quantity and price, and the use of constructor function to ensure the correct state of the card. Creation of a shopping cart management system, emphasizing grouping of items, updating total quantity and price, and the use of constructor function.', 'The need to recreate the shopping cart upon each access is highlighted, with a focus on passing the old card to ensure the correct state of the card. Emphasis on the need to recreate the shopping cart upon each access, passing the old card to ensure the correct state of the card.', 'The process of adding a new item to the shopping cart is explained, detailing the creation of a stored item and updating the quantity and price based on the item being added. Explanation of the process of adding a new item to the shopping cart, including the creation of a stored item and updating the quantity and price.']}], 'duration': 744.876, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M195520.jpg', 'highlights': ["Creating a custom cart object named 'cart.php' in the app folder to store individual products, not just an array of items.", 'The chapter discusses the creation of a shopping cart management system, emphasizing the grouping of items, updating total quantity and price, and the use of constructor function to ensure the correct state of the card.', 'The process of adding a new item to the shopping cart is explained, detailing the creation of a stored item and updating the quantity and price based on the item being added.', "Setting up a new route 'add to cart' in the routes file and configuring it to take a parameter ID for adding items to the cart.", "Creating a function 'get add to cart' in the product controller to handle adding items to the cart and fetching the product using Eloquent by ID.", 'The need to recreate the shopping cart upon each access is highlighted, with a focus on passing the old card to ensure the correct state of the card.']}, {'end': 1190.34, 'segs': [{'end': 974.527, 'src': 'embed', 'start': 940.957, 'weight': 0, 'content': [{'end': 946.685, 'text': "So I'll go back to the product controller to actually use my card.", 'start': 940.957, 'duration': 5.728}, {'end': 953.456, 'text': "Right now I'm only fetching the product, but now I can also fetch my old card if I do have one.", 'start': 947.952, 'duration': 5.504}, {'end': 957.42, 'text': 'So I will use the session facade in Laravel.', 'start': 953.937, 'duration': 3.483}, {'end': 962.664, 'text': 'And to do this, I have to add use session at the top here.', 'start': 957.9, 'duration': 4.764}, {'end': 974.527, 'text': 'and then i use the has method to check if well this session has a card key, so if the card has been stored in the session.', 'start': 964.261, 'duration': 10.266}], 'summary': 'Implement session facade in laravel to fetch stored card data.', 'duration': 33.57, 'max_score': 940.957, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M940957.jpg'}, {'end': 1036.269, 'src': 'embed', 'start': 1004.715, 'weight': 2, 'content': [{'end': 1010.138, 'text': "So now I have the new card and then I'll call the add method.", 'start': 1004.715, 'duration': 5.423}, {'end': 1014.619, 'text': 'to then add my product and the product ID.', 'start': 1011.055, 'duration': 3.564}, {'end': 1022.707, 'text': 'And yes, of course you could just add product and retrieve the ID in the card model, but setting it up this way,', 'start': 1014.979, 'duration': 7.728}, {'end': 1028.973, 'text': "I'm more flexible to also add items which don't have the ID attached to the individual model, for example.", 'start': 1022.707, 'duration': 6.266}, {'end': 1036.269, 'text': "Then I'll access my request and here the session.", 'start': 1031.156, 'duration': 5.113}], 'summary': 'Adding a new card and product id for flexibility in model, accessing request and session.', 'duration': 31.554, 'max_score': 1004.715, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M1004715.jpg'}, {'end': 1148.361, 'src': 'heatmap', 'start': 1114.049, 'weight': 0.903, 'content': [{'end': 1121.857, 'text': "I'll go back here and on my add to cart link I'll add the route product.", 'start': 1114.049, 'duration': 7.808}, {'end': 1124.037, 'text': 'What did I call it?', 'start': 1123.156, 'duration': 0.881}, {'end': 1126.858, 'text': 'I called it product add to cart.', 'start': 1124.057, 'duration': 2.801}, {'end': 1136.703, 'text': 'so product Add to cart and I also need to pass the ID, Which of course can access on my product item here, like this', 'start': 1126.858, 'duration': 9.845}, {'end': 1142.856, 'text': 'So now if I reload this page and If I click add to cart, we get this item.', 'start': 1137.443, 'duration': 5.413}, {'end': 1143.777, 'text': 'We see our cart.', 'start': 1142.876, 'duration': 0.901}, {'end': 1144.898, 'text': 'This looks good.', 'start': 1144.297, 'duration': 0.601}, {'end': 1148.361, 'text': 'We have a total quantity of one and total price of 10, which fits Harry Potter.', 'start': 1144.918, 'duration': 3.443}], 'summary': "Implemented 'add to cart' functionality for product with id, resulting in 1 item and $10 total price.", 'duration': 34.312, 'max_score': 1114.049, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M1114049.jpg'}, {'end': 1156.55, 'src': 'embed', 'start': 1124.057, 'weight': 1, 'content': [{'end': 1126.858, 'text': 'I called it product add to cart.', 'start': 1124.057, 'duration': 2.801}, {'end': 1136.703, 'text': 'so product Add to cart and I also need to pass the ID, Which of course can access on my product item here, like this', 'start': 1126.858, 'duration': 9.845}, {'end': 1142.856, 'text': 'So now if I reload this page and If I click add to cart, we get this item.', 'start': 1137.443, 'duration': 5.413}, {'end': 1143.777, 'text': 'We see our cart.', 'start': 1142.876, 'duration': 0.901}, {'end': 1144.898, 'text': 'This looks good.', 'start': 1144.297, 'duration': 0.601}, {'end': 1148.361, 'text': 'We have a total quantity of one and total price of 10, which fits Harry Potter.', 'start': 1144.918, 'duration': 3.443}, {'end': 1156.55, 'text': 'We have this items array where we then have this group I was referring to with one actually is the ID of the book here.', 'start': 1149.142, 'duration': 7.408}], 'summary': "Implemented 'add to cart' feature for product, showing total quantity of 1 and total price of 10.", 'duration': 32.493, 'max_score': 1124.057, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M1124057.jpg'}], 'start': 940.957, 'title': 'Implementing session handling and creating shopping cart in laravel', 'summary': 'Discusses implementing session handling in laravel, including retrieving and adding cards, and creating a shopping cart with details such as quantity, price, and item information, leading to a functional shopping cart view.', 'chapters': [{'end': 1060.863, 'start': 940.957, 'title': 'Implementing session handling in laravel', 'summary': 'Discusses implementing session handling in laravel, including checking for the existence of a stored card, retrieving it if present, and adding a new card to the session for product management, offering flexibility to add items without attached ids.', 'duration': 119.906, 'highlights': ['The chapter covers using session facade in Laravel to check for the existence of a stored card and retrieve it if present, or pass null if not, for efficient session handling.', 'It explains the process of creating a new card and adding it to the session, offering flexibility to add items without attached IDs for product management.', 'The chapter discusses accessing the request and session to put the card back into it, demonstrating different ways of session handling in Laravel.']}, {'end': 1190.34, 'start': 1061.323, 'title': 'Creating and displaying shopping cart', 'summary': "Covers the process of creating a shopping cart, adding items to the cart, and displaying the cart with details including the total quantity and price, as well as the item's information, using a redirect request and passing product ids and quantities, leading to a functional shopping cart view.", 'duration': 129.017, 'highlights': ["The process of creating a shopping cart, adding items to the cart, and displaying the cart with details including the total quantity and price, as well as the item's information, using a redirect request and passing product IDs and quantities.", 'Adding an item to the session and accessing it through a product index page, which results in displaying the added item in the cart with specific details such as quantity and price.', 'Accessing the product ID and adding it to the shopping cart, leading to the correct display of the item with its details and quantity.']}], 'duration': 249.383, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/4J939dDUH4M/pics/4J939dDUH4M940957.jpg', 'highlights': ['The chapter covers using session facade in Laravel to check for the existence of a stored card and retrieve it if present, or pass null if not, for efficient session handling.', "The process of creating a shopping cart, adding items to the cart, and displaying the cart with details including the total quantity and price, as well as the item's information, using a redirect request and passing product IDs and quantities.", 'It explains the process of creating a new card and adding it to the session, offering flexibility to add items without attached IDs for product management.', 'Adding an item to the session and accessing it through a product index page, which results in displaying the added item in the cart with specific details such as quantity and price.']}], 'highlights': ["Implementing a session-based shopping cart in Laravel allows for persisting user data even if the session hasn't expired yet and enables anonymous users to browse and create a shopping cart.", 'The process of adding a new item to the shopping cart is explained, detailing the creation of a stored item and updating the quantity and price based on the item being added.', 'The chapter covers using session facade in Laravel to check for the existence of a stored card and retrieve it if present, or pass null if not, for efficient session handling.']}