session used to store and pass informatoon from one page to another temporarily until user close the website
https://laravel.com/docs/8.x/session#main-content
its temporarily
laravel seesion can be saved in datrabase, file, encrypted cookies
config/session.php
we can connect to requred database using database.php
mongodb
we can store into database instaed of files and changing some drivers
php artisan session:table
interacting with session
first by request instance and
second method
using global helper method session
session actions
has -> if($request-> session()-> has('learnvern'))
{
echo 'exists';}
learnver key exists and not null above works
if key exists and null or not null below works
if($request-> session()-> exists('learnvern'))
{
echo 'exists';}
missing
exist
missing -> if key is not present - to deternmine it is used
push to arra sesion value
$request->session()->push('user.teams', 'developers');
retrieve and delete
$value = $request->session()->pull('key', 'default');
$value = $request->session()->forget('key');
incrimenting and decriment
may use the increment
and decrement
methods:
how many tomes refresh
$request->session()->increment('count'); $request->session()->increment('count', $incrementBy = 2); $request->session()->decrement('count'); $request->session()->decrement('count', $decrementBy = 2);
flash data
it wil store upto next request , after that it will delete
$request->session()->flash('status', 'Task was successful!');
regenreate the session
for every time authetnication regenearte the session
$request->session()->regenerate();
before regenerate delete the data iusing ivalidate
$request->session()->invalidate();
session flaseh
for example payment over, sucesfule message wil show upto next request
$request->session()->flash('msg','welcome to learn vern');
if (session()->has('sucess')
{{ sesion('success') }}
reflash method
$request->session()->reflash();
till close window
$request->session()->keepp('msg','siccess');
_____ provide a way to store information about the user across multiple requests.
Marked Answer : session
Correct Answer : session
Which session driver is not supported in Laravel?
Marked Answer : dynamodb
Correct Answer : None of the above
file,redis,dynamodb
Which helper is used to work with session data?
Marked Answer : session()
Correct Answer : session()
How to retrieve all the data in the session?
Marked Answer : $request->session()->all();
Correct Answer : $request->session()->all();
Which is the correct way to store data in the session?
Marked Answer : session(['key' => 'value']);
Correct Answer : A and B both
Data stored in the session using ______ method will be available immediately and during the subsequent HTTP request.
Marked Answer : flash()
Correct Answer : flash()
No comments:
Post a Comment