60 likes | 113 Views
Here learn about http session. All http driven application are stateless. Session provide a way to store information about the user across multiple requests. Laravel provides various drivers like file, cookies, array and database to handle session data. By default file driver is used because it is lightweight session can be configured using its configuration file.
E N D
WELCOME TO DUCAT INDIA Laravel Sessions
Laravel provides various drivers like file, cookies, array and database to handle session data. By default file driver is used because it is lightweight session can be configured using its configuration file. So, let’s see the session configuration file. • – Open the visual studio and go inside the config directory and in config folder open “session.php” file. Let’s see how you can use a session in Laravel 8. • – For this create new controller. So switch to command prompt and run the command as-: Php artisan make: controller SessionController • And then press enter and controller created successfully. • Now run the application so write- Php artisan serve
Now go to project i.e. visual studio and open app> Http> Controllers> SessionController.php file. Inside file create the controller and then inside it create a function for access the system data. < ? php Namespace App\Http\Controllers; Use Illuminate\Http\Request; Class SessionController extends Controller { Public function getSessionData(Request $request) { } Put if condition in function. Inside if condition just gives session value. < ? php Namespace App\Http\Controllers; Use Illuminate\Http\Request; Class SessionController extends Controller { Public function getSessionData(Request $request) { If ($request->session () ->has (‘name’)) { Echo $request->session () ->get(’name’) } }
Let’s get session method to retrieve data from session by its key name. If session case is not present then just return a message. So write further else () with echo ()-: < ? php Namespace App\Http\Controllers; Use Illuminate\Http\Request; Class SessionController extends Controller { Public function getSessionData(Request $request) { If ($request->session () ->has (‘name’)) { Echo $request->session () ->get(’name’) } ……..Read More (https://tutorials.ducatindia.com/php/laravel-sessions/)
THANK YOU CONTACT:- 70-70-90-50-90 www.ducatindia.com