Laravel - Session

Laravel utilizes free element rich library SwiftMailer to send messages. Quick Mailer library work is simple we can undoubtedly send messages without an excessive number of hassles.The email layouts are stacked similarly as views.which implies you can utilize the Blade linguistic structure and infuse information into your formats.

Sessions are utilized to store data about the client over the solicitations. Laravel gives different drivers like document, treat, apc, cluster, Memcached, Redis, and database to deal with session information.

Storing Session Data

Data can be put away in session utilizing the put() technique. The put() strategy will take two contentions, the "key" and the "value".

$request->session()- >put('key', 'esteem'); 

Deleting Session Data

The forget() technique is utilized to erase a thing from the session. This strategy will take key as the argument.

$request->session()- >forget('key'); 

Use flush() technique rather than forget() strategy to erase all session information. Utilize the pull() technique to recover information from session and erase it a short time later. The force() technique will likewise take key as the contention. The contrast between the forget() and the pull() strategy is that forget() technique won't restore the estimation of the session and pull() strategy will return it and erase that esteem from session.


Step 1 − Create a controller called SessionController by executing the accompanying command.

php craftsman make:controller SessionController - plain 

Step 2 − After fruitful execution, you will get the accompanying yield −

Step 3 − Copy the accompanying code in a document at




namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Http\Controllers\Controller; 

class SessionController extends Controller { 

public function accessSessionData(Request $request){ 

if($request->session()- >has('my_name')) 

reverberation $request->session()- >get('my_name'); 


reverberation 'No information in the session'; 


public function storeSessionData(Request $request){ 

$request->session()- >put('my_name','Virat Gandhi'); 

reverberation "Data has been added to session"; 


public function deleteSessionData(Request $request){ 

$request->session()- >forget('my_name'); 

reverberation "Data has been expelled from session."; 



Step 4 − Add the accompanying lines at app/Http/routes.php file.





Step 5 − Visit the accompanying URL to set information in session.


Step 6 − The yield will show up as appeared in the accompanying image.

Stage 7 − Visit the accompanying URL to get information from session. http://localhost:8000/session/get Stage 8 − The yield will show up as appeared in the accompanying picture. Stage 9 − Visit the accompanying URL to expel session information. http://localhost:8000/session/expel