mercredi 3 février 2016

Laravel redirect with session message does not always persist to my request

I have an Admin tool built with Laravel where users can perform certain actions on individual records.

The way the code is built I am performing a post to a URL, executing the necessary code, updating the database and then redirecting back with a session message.

Controller Code:

return Redirect::back()->with("msg_success", "SMS has been sent!");

Now the page that gets rendered from the redirect has a check at the top to display the session message if it exists.

View Code:

@if (Session::has('msg_success'))
<div class="col-lg-10">
    <div role="alert" class="alert alert-success alert-dismissible fade in">
        <button aria-label="Close" data-dismiss="alert" class="close" type="button"><span aria-hidden="true">×</span></button>
        <strong>Success! </strong>{{ Session::get('msg_success') }}
    </div>
</div>
<div class="clearfix"></div>
@endif

For some reason, sometimes the message is displayed and other times it is not. I cant for the life of me figure out why. Could it be middle ware that is intercepting the request and then performing another request and it is getting destroyed? I do not see anything in there that looks like it would cause this.

Any ideas would help. I thought about using a URL parameter when redirecting like

return Redirect::to('explicitURL?success=whateverthesuccesmessageis')

But I would prefer not do this as my action is shared among different URL's.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire