What is the session like in Laravel 6?

Tram Ho

1. What is session?

Session in English is the session. Yes, the session helps us save a user’s session. A session takes effect when you attach and lose when you delete or close the browser. Sessions are very useful for us to authenticate users so they are very useful for developers.

2. How to use the session in Laravel 6

2.1 Get the session

2.1.1 Obtained via Request

If the session does not exist, how to handle it?

2.1.2 Taken through Session

2.1.3 Retrieve all Session data

$data = $request->session()->all();

2.1.4 Check for session availability

2.1.5 Use once and then discard

2.1.6 Delete session

Conclude

So I have instructed you to use Session in laravel 6. I myself think that it is better to remember only one way of use than to remember many ways because they work similarly. Personally, I use Request to do everything with the session because it’s more convenient.

Share the news now

Source : Viblo