Sunday, March 5, 2017

pass HTML content on laravel flash/redirection message

I need to send HTML content on laravel flash message with some links on it . I am still not sure what is best practice for it.

In my case I need to redirect users to some page if they input soft deleted data and prompt them to undelete. I tried below

$checkDeleted=Tracker::onlyTrashed()->where('imei','=',$request->input("imei"))->get();
                //echo $checkDeleted[0]->id;
                //die;
                if(@$checkDeleted[0]->id!=''){ //means the trashed data is  there
                    $yes='<button type="button" class="btn btn-labeled btn-success">
                            <span class="btn-label">
                            <i class="glyphicon glyphicon-ok"></i>
                            </>Success
                        </button>';
                    $no='<button type="button" class="btn btn-labeled btn-success">
                            <span class="btn-label">
                            <i class="glyphicon glyphicon-ok"></i>
                            </>Success
                        </button>';

                    return redirect()->route('trackers.index')->with('warning', 'The tracker this IMEI was deleted from system at '.$checkDeleted[0]->deleted_at. " do you want to restore it?.".$yes.$no);
                    //return redirect()->route('trackers.index')->with('warning', 'trackers.error');

                }

The redirection message looks like below enter image description here

I also made the seperate blade template as suggested by https://laracasts.com/discuss/channels/laravel/how-to-get-html-in-response-session-flash-or-redirect-with-messages but I was unable to render it in my flash message. Any help will be appreciated



via sumit

Advertisement