How to use session in laravel
This article introduces the knowledge of "how to use session in laravel". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Usage: 1, store data, syntax is "session ()-> put ('key1',' value1')"; 2, get data, syntax is "session ()-> all ()"; 3, clear or delete data, syntax is "session ()-> pull ('key3');"
This article operating environment: Windows10 system, Laravel6 version, Dell G3 computer.
What is the use of session in laravel
1. Store data
Store a single piece of data, the following two writing methods have the same function, and then use session () as an example to demonstrate
$request- > session ()-> put ('key1',' value1'); session ()-> put ('key2',' value2')
Storage array
For ($item1 witching ipush ('key4',' name_'.$i);}
Session temporarily stores data (data can only be accessed once)
Session ()-> flash ('key5',' value5'); Session ()-> reflash (); / / call this method before all (), get (), etc. Flash data will be saved all the time.
two。 Get data
Get all the data
Session ()-> all ()
Get a single piece of data according to the key, and the second parameter is the default value
Session ()-> get ('key5',' default_value')
3. Clear or delete data
Delete data according to key and return at the same time
Session ()-> pull ('key3')
Delete key
Session ()-> forget ('key3')
Clear all session
Session ()-> flush ()
4. Determine whether session exists or not
Session ()-> has ('key4') "how to use session in laravel" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!