Set Session Variables In Laravel
In vanilla PHP, I can set a session variable using the below code;
$_SESSION['blog'] = array( "email" => $_POST['email'], "password" => $password, "firstname" => $row ['firstName'], "lastname" => $row ['lastName'], "id" => $row ['id'] );
How can I do the same in
FYI I'm not talking about the default session name eg
laravel_session. I have multiple session variables for parts of my site such as
blog, 'careers' and I name them just like the code above and able to check and access them individually. So one user can have all three sessions variables at the same time but for different sections of the site.
One way you could do it:
$vars = [ "email" => $email, "password" => $password, "firstname" => $row['firstName'], "lastname" => $row['lastName'], "id" => $row['id'] ]; session()->put('blog', $vars);
Update: To check existence of a session variable:
session()->has('blog'); // bool
Update: To get an element contained in the session variable 'blog'
session('blog.id'); // using the dot notation
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?