Not a big fan of the provided solutions (that is: several variables, helper classes, loops on "possibly existing variables"). Below is a solution that uses an array instead, rather than two separate variables. It is also easily extensible to handle multiple errors if you want, but for simplicity, I saved it in a single flash message:
Redirection with an array of flash messages:
return redirect('/admin/permissions')->with('flash_message', ['success','Updated Successfully','Permission "'. $permission->name .'" updated successfully!']);
Output based on the contents of the array:
@if(Session::has('flash_message')) <script type="text/javascript"> jQuery(document).ready(function(){ bootstrapNotify('{{session('flash_message')[0]}}','{{session('flash_message')[1]}}','{{session('flash_message')[2]}}'); }); </script> @endif
Not relevant, as you can have your own notification method / plugin - but just for clarity - bootstrapNotify simply triggers a boot notification from http://bootstrap-notify.remabledesigns.com/ :
function bootstrapNotify(type,title = 'Notification',message) { switch (type) { case 'success': icon = "la-check-circle"; break; case 'danger': icon = "la-times-circle"; break; case 'warning': icon = "la-exclamation-circle"; } $.notify({message: message, title : title, icon : "icon la "+ icon}, {type: type,allow_dismiss: true,newest_on_top: false,mouse_over: true,showProgressbar: false,spacing: 10,timer: 4000,placement: {from: "top",align: "right"},offset: {x: 30,y: 30},delay: 1000,z_index: 10000,animate: {enter: "animated bounce",exit: "animated fadeOut"}}); }