Skip to content

Commit e403cc8

Browse files
committed
feat: update flash message docs
1 parent 36b914b commit e403cc8

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/docs/http/flash.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
11
# Session Flash
22

3-
Session flash allows you to store data in the session for a single request. This is useful for scenarios like displaying a message after a form submission. Leaf provides a straightforward way to work with flash messages.
3+
Session flash allows you to store data in the session for a single request. This is useful for scenarios like displaying a message after a form submission or passing data from one request to another.
44

55
## Adding a new flash
66

7-
You can set a new flash item using the `set()` method. It method accepts two arguments:
7+
You can add a new flash message to a response using the `withFlash()` method. This method accepts two arguments:
88

9-
- The item to flash
10-
- The key to save it under. The key is optional and defaults to `message`.
9+
- The name of the flash message
10+
- The value of the flash message
11+
12+
```php:no-line-numbers
13+
response()->withFlash('message', 'something');
14+
```
15+
16+
You can chain the `withFlash()` method with your main response methods to return a response with a flash message.
1117

1218
```php
13-
flash()->set('This is my message');
14-
flash()->set('This is my message', 'info');
19+
response()
20+
->withFlash('message', 'something')
21+
->json('...');
1522
```
1623

1724
You are not limited to strings. You can flash different types of data:
1825

1926
```php
20-
flash()->set($userObject);
21-
flash()->set($userArray);
22-
flash()->set($userString);
23-
flash()->set($userInt);
27+
response()->withFlash('object', $userObject)->json('...');
28+
response()->withFlash('array', $userArray)->json('...');
29+
response()->withFlash('string', $userString)->json('...');
30+
response()->withFlash('int', $userInt)->json('...');
2431
```
2532

2633
## Display a flash item
2734

2835
To display a flash item, you can use the `display()` method. This method accepts the key of the item to get. If the key is not provided, it defaults to `message`.
2936

30-
```php
31-
echo flash()->display();
37+
```php:no-line-numbers
38+
$message = flash()->display();
3239
```
3340

34-
If you set a flash item with a key, you can pass the key to the `display()` method to get the item.
41+
If you set a flash item with a different key, you can pass the key to the `display()` method to get the item.
3542

3643
```php
37-
flash()->set('This is my message', 'info');
38-
...
39-
40-
echo flash()->display('info');
44+
$message = flash()->display('info');
45+
$object = flash()->display('object');
46+
$array = flash()->display('array');
4147
```
4248

4349
The item will be removed from the session after it has been displayed.
4450

4551
## Manually removing a flash item
4652

47-
You may choose to remove a flash item manually using the `remove()` method. This method accepts the key of the item to remove.
53+
You may choose to remove a flash item manually without displaying it first. You can do this by calling the `remove()` method with the key of the item to remove.
4854

49-
```php
55+
```php:no-line-numbers
5056
flash()->remove('info');
5157
```

src/docs/http/response.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ Leaf allows you to set flash messages for your response using the `withFlash()`
333333
- The name of the flash message
334334
- The value of the flash message
335335

336-
```php
336+
```php:no-line-numbers
337337
response()->withFlash('message', 'something');
338338
```
339339

0 commit comments

Comments
 (0)