mercredi 16 novembre 2016

How to pass multiple flash warning message with laravel 5

Laravel can only show one message by type of messages (danger, warning, success, info). There is a solution for passing many warning message (for example) :

In the controller send a tab :

    $messages = ['test warning 1',
                'test warning 2'
    ];
    $request->session ()->flash ( 'alert-warning', $messages );

And in the php view :

        <div class="flash-message">
        <ul>
            @foreach (['danger', 'warning', 'success', 'info'] as $type_message)
                @if(Session::has('alert-' . $type_message))
                    @foreach (Session::get('alert-' . $type_message) as $message)
                    <li><p class="alert alert-"></p></li>
                    @endforeach
                @endif
            @endforeach
        </ul>
    </div>
    @endif <!-- end .flash-message -->

An example of the css :

.flash-message {
    border-width: 0.2 em;
    border-style: dashed;
    border-color: grey;
}

.alert {
    font-size: 1 em;
    font-weight: 800;
}

.alert-danger {
    color : #ff6c00;
}

.alert-warning {
    color : #FFD700;
}

.alert-success {
    color : green;
}

.alert-info {
    color : blue;
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire