Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,45 @@ class BookController
flash()->add{{ type | capitalize }}('{{ message }}', '{{ title }}');
```

<p id="preset-variables"><a href="#preset-variables" class="anchor"><i class="fa-duotone fa-link"></i> Variables</a></p>

Presets can also contain variables that can be substituted by using the translation system. Take the following example where you have a preset showing a personalised welcome message to the user.

```php
<?php // config/flasher.php

return [
'presets' => [
'hello_user' => [
'type' => '{{ type }}',
'message' => 'welcome_back_user',
],
],
];
```

In the translations file you can define `welcome_back_user` with the message containing the variable `:username`.

```php
<?php // /resources/lang/vendor/flasher/en/messages.php

return [
'welcome_back_user' => 'Welcome back :username',
];
```

If you want to substitute the `:username` in the above translation with a username in the controller, you can achieve this by passing an array of values to be substituted as the second argument.

```php
class BookController
{
public function save()
{
$username = 'John Doe';

flash()->addPreset('hello_user', ['username' => $username]);
```

---

## <i class="fa-duotone fa-list-radio"></i> Dark Mode
Expand Down
34 changes: 34 additions & 0 deletions docs/symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,40 @@ class BookController
flash()->add{{ type | capitalize }}('{{ message }}', '{{ title }}');
```

<p id="preset-variables"><a href="#preset-variables" class="anchor"><i class="fa-duotone fa-link"></i> Variables</a></p>

Presets can also contain variables that can be substituted by using the translation system. Take the following example where you have a preset showing a personalised welcome message to the user.

```yaml
# config/packages/flasher.yaml

flasher:
presets:
hello_user:
type: {{ type }}
message: welcome_back_user
```

In the translations file you can define `welcome_back_user` with the message containing the variable `:username`.

```yaml
# translations/flasher.en.yaml

welcome_back_user: Welcome back :username
```

If you want to substitute the `:username` in the above translation with a username in the controller, you can achieve this by passing an array of values to be substituted as the second argument.

```php
class BookController
{
public function save()
{
$username = 'John Doe';

flash()->addPreset('hello_user', ['username' => $username]);
```

---

## <i class="fa-duotone fa-list-radio"></i> Dark Mode
Expand Down