Reputation: 1860
I am using jQuery Ajax function to validate user and create session. In laravel controller i have the following code.
if( isset( $_POST['email'] ) )
{
$email = $_POST['email'];
$password = $_POST['password'];
$results = DB::table('table')->where([
['school_email', '=', $email ],
['school_password', '=', $password],
])->get() ;
if( $results -> count() == 0 )
{
echo json_encode( array('data' => '0' ) ); exit;
}
else
{
$user = $results[0] ;
session(['users' => $user ]);
$request -> session() -> put('two', 'test');
echo json_encode( array( 'data' => '1' ) );
exit;
}
Session is set when i print it after setting session variable.But when i refresh the page or redirect user to another url. session is coming as empty variable. I am using file session with default settings and directory (storage) is writable. I did change server.php to index.php and copied htaccess from public directory to root just to access my local site with out writing public in url. e.g http://localhost/site2/login before it was
http://localhost/site2/public/login
Upvotes: 0
Views: 270
Reputation: 1860
We need to use $request -> session() -> save(); after assigning value to session variable. Strange it was not pointed any where in document.
Upvotes: 0