# [Usage](../../../usage.md) > Session messages
This framework uses SweetAlert2 to deliver messages to the front-end, based on session.\
You can locate the session-messages component in:
```
resources/views/components/ui/session-messages.blade.php
```
---
## Usage
You must include this in your general layout or in a view:
```html
<x-kfw::session-messages />
```
Example:
```html
<html>
    <head>
        <x-kfw::assets />
    </head>
    <body>
        @yield('content')
        <x-kfw::session-messages />
    </body>
</html>
```

If using the:
```html
<x-kfw::ui>
    <!-- content here -->
</x-kfw::ui>
```
the session messages are already included.

From the controllers, then add based on the messages. Examples:\
To display a success message:
```php
return back()->with(['success' => "Here your success message."]);
```
To display an error message:
```php
return back()->with(['error' => "Here your error message."]);
```
To display a warning message:
```php
return back()->with(['warning' => "Here your warning message."]);
```

## Personalization
In `session-messages.blade.php` you can change the SweetAlert2 options, including timing, icons, progress bar and buttons.

Or, you can set the attributes:
```html
<x-kfw::session-messages 
    :successTimer="2000"
    :errorTimer="0"
    :warningTimer="0"
/>
```

- **:successTimer**  
Set the timer for the **success** message before goes out, in milliseconds. Setting it to `0`, will disable the timer and the progress bar, showing an "Ok" button instead.  
  _[INTEGER]_  
  *default*: `2000`


- **:errorTimer**  
Set the timer for the **error** message before goes out, in milliseconds. Setting it to `0`, will disable the timer and the progress bar, showing an "Ok" button instead.  
  _[INTEGER]_  
    *default*: `0`


- **:warningTimer**  
Set the timer for the **warning** message before goes out, in milliseconds. Setting it to `0`, will disable the timer and the progress bar, showing an "Ok" button instead.  
  _[INTEGER]_  
    *default*: `0`


Error can also display error log, by passing it:
```php
return back()->with(['error' => "Here your error message.", 'errorlog' => 'This is the log.']);
```

Or, you can just use the method of the `ResponseHelper` class:

```php
class ResponseHelper {

    public static function returnBackSuccess($message = null) {

        if(isset($message)) {
            return back()->with('success', $message);
        }

        return back()->with('success');
    }

    public static function returnJsonSuccess($message = null) {

        if(isset($message)) {
            return response()->json(['success' => $message]);
        }

        return response()->json(['success']);
    }
    
    public static function returnJsonGenericError($e = null) {
        
        if(isset($e)) {
            Log::error($e);
            return response()->json(['error' => __('kfw::ui.generic_error'), 'errorlog' => $e->getMessage()]);
        }
        
        return response()->json(['error' => __('kfw::ui.generic_error')]);
    }
    
    public static function returnBackGenericError($e = null) {

        if(isset($e)) {
            Log::error($e);
            return back()->with(['error' => __('kfw::ui.generic_error'), 'errorlog' => $e->getMessage()]);
        }

        return back()->with(['error' => __('kfw::ui.generic_error')]);
    }

    public static function returnJsonError($message = null, $e = null) {

        if(isset($e)) {
            Log::error($e);
            return response()->json(['error' => $message ?? __('kfw::ui.generic_error'), 'errorlog' => $e->getMessage()]);
        }

        return response()->json(['error' => $message ?? __('kfw::ui.generic_error')]);
    }

    public static function returnBackError($message = null, $e = null) {

        if(isset($e)) {
            Log::error($e);
            return back()->with(['error' => $message ?? __('kfw::ui.generic_error'), 'errorlog' => $e->getMessage()]);
        }

        return back()->with(['error' => $message ?? __('kfw::ui.generic_error')]);
    }
}
```