Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use session in laravel

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report