[{"data":1,"prerenderedAt":2562},["ShallowReactive",2],{"article-20230404-vue3-toastify-inertia":3},{"article":4,"surround":2556},{"id":5,"title":6,"authorKey":7,"body":8,"codeLinks":2518,"createdAt":2522,"description":2523,"excerpt":2524,"extension":2541,"image":2542,"meta":2543,"navigation":193,"path":2544,"published":2545,"readingTime":225,"revisedAt":2546,"seo":2547,"stem":2548,"tags":2549,"__hash__":2555},"articles\u002Farticles\u002F20230404-vue3-toastify-inertia.md","Vue3-Toastify in a Laravel\u002FInertia\u002FVue project","philip",{"type":9,"value":10,"toc":2513},"minimark",[11,26,41,44,72,96,102,107,138,141,149,420,427,476,489,498,722,725,729,740,1225,1236,1251,1669,1672,1756,1769,1934,1940,2159,2166,2194,2197,2223,2226,2236,2240,2243,2260,2270,2422,2425,2503,2509],[12,13,14,15],"p",{},"Need a full-featured toast notification component for your next Vue.js project? Don't look any further: ",[16,17,18,25],"strong",{},[19,20,24],"a",{"href":21,"rel":22},"https:\u002F\u002Fgithub.com\u002Fjerrywu001\u002Fvue3-toastify",[23],"nofollow","Vue3-Toastify"," beats it all!",[12,27,28,29,34,35,40],{},"Previously I have tried ",[19,30,33],{"href":31,"rel":32},"https:\u002F\u002Fvue-toastification.maronato.dev\u002F",[23],"Vue Toastification"," («Light, easy and beautiful toasts») and ",[19,36,39],{"href":37,"rel":38},"https:\u002F\u002Fszboynono.github.io\u002Fmosha-vue-toastify\u002F",[23],"Mosha Vue Toastify"," («A light weight and fun Vue 3 toast or notification or snack bar») but they are both kind of outdated and abandoned projects with latest releases dating back to prehistoric 2021. Let me show you how to integrate great looking and easy to use toast notifications into your VILT stack!",[12,42,43],{},"I first started to build my own toast component but soon ended up struggling with challenging states and animations as those were my (minimal) requirements:",[45,46,47,51,54,57,60,63,66,69],"ul",{},[48,49,50],"li",{},"Support multiple toasts",[48,52,53],{},"Autoclose with progress bar (success)",[48,55,56],{},"No auto-close on warning\u002Ferror",[48,58,59],{},"Styled for info\u002Fsuccess\u002Fwarning\u002Ferror notifications, playing nicely with Tailwind",[48,61,62],{},"Close on click",[48,64,65],{},"Pause on hover",[48,67,68],{},"Newest on top",[48,70,71],{},"Bounce transition",[12,73,74,77,78,83,84,89,90,95],{},[19,75,24],{"href":21,"rel":76},[23]," offers it all, built-in, fully customizable, and «beautiful by default»! The ",[19,79,82],{"href":80,"rel":81},"https:\u002F\u002Fgithub.com\u002Fjerrywu001",[23],"author"," is not lying – look at this great ",[19,85,88],{"href":86,"rel":87},"https:\u002F\u002Fvue3-toastify.js-bridge.com\u002Fget-started\u002Fintroduction.html",[23],"feature set"," and the ",[19,91,94],{"href":92,"rel":93},"https:\u002F\u002Fvue3-toastify.js-bridge.com\u002F",[23],"demo",". Even the documentation couldn't be more detailed and simply crystal clear!",[97,98,99],"blockquote",{},[12,100,101],{},"But hey, it's just a toast! Does it deserve its own blogpost? Definitely! I am a huge fanboy of that component, how well it is designed and how easy it is to use. 👏",[103,104,106],"h2",{"id":105},"integrate-vue3-toastify-into-vilt","Integrate Vue3-Toastify into VILT",[12,108,109,110,115,116,115,121,115,126,131,132,137],{},"Let me now show you how to integrate Vue3-Toastify into a project built on VILT (",[19,111,114],{"href":112,"rel":113},"https:\u002F\u002Fvuejs.org\u002F",[23],"Vue3",", ",[19,117,120],{"href":118,"rel":119},"https:\u002F\u002Finertiajs.com\u002F",[23],"Inertia.js",[19,122,125],{"href":123,"rel":124},"https:\u002F\u002Flaravel.com\u002F",[23],"Laravel",[19,127,130],{"href":128,"rel":129},"https:\u002F\u002Ftailwindcss.com\u002F",[23],"Tailwind",") stack, bootstrapped with ",[19,133,136],{"href":134,"rel":135},"https:\u002F\u002Fjetstream.laravel.com",[23],"Jetstream",".",[12,139,140],{},"Our goal is to fire flash messages from the backend, potentially more than one per request. The flash messages should be displayed in our frontend and stay open even when navigating to other pages. They should be easy closable, and the success messages should auto-close after some seconds.",[12,142,143,144,148],{},"Let's start by importing the CSS and loading the Vue3Toastify component in ",[145,146,147],"code",{},"resources\u002Fjs\u002Fapp.js"," (stripped down to the bare metal):",[150,151,157],"pre",{"className":152,"code":153,"filename":154,"language":155,"meta":156,"style":156},"language-js shiki shiki-themes github-light-default github-light-default github-dark-default","import '.\u002Fbootstrap'\nimport 'vue3-toastify\u002Fdist\u002Findex.css'\nimport '..\u002Fcss\u002Fapp.css'\n\nimport { createApp, h } from 'vue'\nimport { createInertiaApp } from '@inertiajs\u002Fvue3'\nimport { resolvePageComponent } from 'laravel-vite-plugin\u002Finertia-helpers'\nimport Vue3Toastify from 'vue3-toastify'\n\ncreateInertiaApp({\n    resolve: (name) => resolvePageComponent(`.\u002FPages\u002F${name}.vue`, import.meta.glob('.\u002FPages\u002F**\u002F*.vue')),\n    setup({ el, App, props, plugin }) {\n        return createApp({ render: () => h(App, props) })\n            .use(plugin)\n            .use(Vue3Toastify)\n            .mount(el)\n    },\n})\n","app.js","js","",[145,158,159,172,180,188,195,210,223,236,249,254,264,320,350,375,387,397,408,414],{"__ignoreMap":156},[160,161,164,168],"span",{"class":162,"line":163},"line",1,[160,165,167],{"class":166},"s5nWI","import",[160,169,171],{"class":170},"s-BGO"," '.\u002Fbootstrap'\n",[160,173,175,177],{"class":162,"line":174},2,[160,176,167],{"class":166},[160,178,179],{"class":170}," 'vue3-toastify\u002Fdist\u002Findex.css'\n",[160,181,183,185],{"class":162,"line":182},3,[160,184,167],{"class":166},[160,186,187],{"class":170}," '..\u002Fcss\u002Fapp.css'\n",[160,189,191],{"class":162,"line":190},4,[160,192,194],{"emptyLinePlaceholder":193},true,"\n",[160,196,198,200,204,207],{"class":162,"line":197},5,[160,199,167],{"class":166},[160,201,203],{"class":202},"s_bOF"," { createApp, h } ",[160,205,206],{"class":166},"from",[160,208,209],{"class":170}," 'vue'\n",[160,211,213,215,218,220],{"class":162,"line":212},6,[160,214,167],{"class":166},[160,216,217],{"class":202}," { createInertiaApp } ",[160,219,206],{"class":166},[160,221,222],{"class":170}," '@inertiajs\u002Fvue3'\n",[160,224,226,228,231,233],{"class":162,"line":225},7,[160,227,167],{"class":166},[160,229,230],{"class":202}," { resolvePageComponent } ",[160,232,206],{"class":166},[160,234,235],{"class":170}," 'laravel-vite-plugin\u002Finertia-helpers'\n",[160,237,239,241,244,246],{"class":162,"line":238},8,[160,240,167],{"class":166},[160,242,243],{"class":202}," Vue3Toastify ",[160,245,206],{"class":166},[160,247,248],{"class":170}," 'vue3-toastify'\n",[160,250,252],{"class":162,"line":251},9,[160,253,194],{"emptyLinePlaceholder":193},[160,255,257,261],{"class":162,"line":256},10,[160,258,260],{"class":259},"sd69k","createInertiaApp",[160,262,263],{"class":202},"({\n",[160,265,267,270,273,277,280,283,286,289,292,294,297,299,301,303,307,309,312,314,317],{"class":162,"line":266},11,[160,268,269],{"class":259},"    resolve",[160,271,272],{"class":202},": (",[160,274,276],{"class":275},"sQJ0q","name",[160,278,279],{"class":202},") ",[160,281,282],{"class":166},"=>",[160,284,285],{"class":259}," resolvePageComponent",[160,287,288],{"class":202},"(",[160,290,291],{"class":170},"`.\u002FPages\u002F${",[160,293,276],{"class":202},[160,295,296],{"class":170},"}.vue`",[160,298,115],{"class":202},[160,300,167],{"class":166},[160,302,137],{"class":202},[160,304,306],{"class":305},"sDkKp","meta",[160,308,137],{"class":202},[160,310,311],{"class":259},"glob",[160,313,288],{"class":202},[160,315,316],{"class":170},"'.\u002FPages\u002F**\u002F*.vue'",[160,318,319],{"class":202},")),\n",[160,321,323,326,329,332,334,337,339,342,344,347],{"class":162,"line":322},12,[160,324,325],{"class":259},"    setup",[160,327,328],{"class":202},"({ ",[160,330,331],{"class":275},"el",[160,333,115],{"class":202},[160,335,336],{"class":275},"App",[160,338,115],{"class":202},[160,340,341],{"class":275},"props",[160,343,115],{"class":202},[160,345,346],{"class":275},"plugin",[160,348,349],{"class":202}," }) {\n",[160,351,353,356,359,361,364,367,369,372],{"class":162,"line":352},13,[160,354,355],{"class":166},"        return",[160,357,358],{"class":259}," createApp",[160,360,328],{"class":202},[160,362,363],{"class":259},"render",[160,365,366],{"class":202},": () ",[160,368,282],{"class":166},[160,370,371],{"class":259}," h",[160,373,374],{"class":202},"(App, props) })\n",[160,376,378,381,384],{"class":162,"line":377},14,[160,379,380],{"class":202},"            .",[160,382,383],{"class":259},"use",[160,385,386],{"class":202},"(plugin)\n",[160,388,390,392,394],{"class":162,"line":389},15,[160,391,380],{"class":202},[160,393,383],{"class":259},[160,395,396],{"class":202},"(Vue3Toastify)\n",[160,398,400,402,405],{"class":162,"line":399},16,[160,401,380],{"class":202},[160,403,404],{"class":259},"mount",[160,406,407],{"class":202},"(el)\n",[160,409,411],{"class":162,"line":410},17,[160,412,413],{"class":202},"    },\n",[160,415,417],{"class":162,"line":416},18,[160,418,419],{"class":202},"})\n",[12,421,422,423,426],{},"Import vue3-toastify's CSS before your ",[145,424,425],{},"app.css",", so you could override some styles there, e.g.:",[150,428,432],{"className":429,"code":430,"filename":425,"language":431,"meta":156,"style":156},"language-css shiki shiki-themes github-light-default github-light-default github-dark-default",":root {\n    --toastify-toast-width: 400px;\n    --toastify-color-warning: #ec9b00;\n}\n","css",[145,433,434,442,459,471],{"__ignoreMap":156},[160,435,436,439],{"class":162,"line":163},[160,437,438],{"class":305},":root",[160,440,441],{"class":202}," {\n",[160,443,444,447,450,453,456],{"class":162,"line":174},[160,445,446],{"class":275},"    --toastify-toast-width",[160,448,449],{"class":202},": ",[160,451,452],{"class":305},"400",[160,454,455],{"class":166},"px",[160,457,458],{"class":202},";\n",[160,460,461,464,466,469],{"class":162,"line":182},[160,462,463],{"class":275},"    --toastify-color-warning",[160,465,449],{"class":202},[160,467,468],{"class":305},"#ec9b00",[160,470,458],{"class":202},[160,472,473],{"class":162,"line":190},[160,474,475],{"class":202},"}\n",[12,477,478,479,484,485,488],{},"(see ",[19,480,483],{"href":481,"rel":482},"https:\u002F\u002Fvue3-toastify.js-bridge.com\u002Fusage\u002Fhow-to-style.html",[23],"How to style"," docs for all available ",[145,486,487],{},"--toastify-*"," CSS variables)",[12,490,491,492,497],{},"You could now fire a toast message from anywhere in your JS code like this (see ",[19,493,496],{"href":494,"rel":495},"https:\u002F\u002Fvue3-toastify.js-bridge.com\u002Fapi\u002Ftoast.html#usages",[23],"Usages","):",[150,499,501],{"className":152,"code":500,"language":155,"meta":156,"style":156},"import { toast } from 'vue3-toastify'\n\nconst options = {\n  autoClose: 5000,\n  type: toast.TYPE.SUCCESS,\n  newestOnTop: true,\n  theme: toast.THEME.COLORED,\n  \u002F\u002F and so on ...\n} as ToastOptions;\n\n\u002F\u002F display toasts\nconst toastId = toast(\"Hello\", options as ToastOptions);\n\n\u002F\u002Fshortcut to different types\ntoast.success(\"Hello\", options as ToastOptions);\ntoast.info(\"World\", options as ToastOptions);\ntoast.warn(MyComponent, options as ToastOptions);\ntoast.error(\"Error\", options as ToastOptions);\n",[145,502,503,514,518,531,542,557,567,582,588,601,605,610,637,641,646,666,686,702],{"__ignoreMap":156},[160,504,505,507,510,512],{"class":162,"line":163},[160,506,167],{"class":166},[160,508,509],{"class":202}," { toast } ",[160,511,206],{"class":166},[160,513,248],{"class":170},[160,515,516],{"class":162,"line":174},[160,517,194],{"emptyLinePlaceholder":193},[160,519,520,523,526,529],{"class":162,"line":182},[160,521,522],{"class":166},"const",[160,524,525],{"class":305}," options",[160,527,528],{"class":166}," =",[160,530,441],{"class":202},[160,532,533,536,539],{"class":162,"line":190},[160,534,535],{"class":202},"  autoClose: ",[160,537,538],{"class":305},"5000",[160,540,541],{"class":202},",\n",[160,543,544,547,550,552,555],{"class":162,"line":197},[160,545,546],{"class":202},"  type: toast.",[160,548,549],{"class":305},"TYPE",[160,551,137],{"class":202},[160,553,554],{"class":305},"SUCCESS",[160,556,541],{"class":202},[160,558,559,562,565],{"class":162,"line":212},[160,560,561],{"class":202},"  newestOnTop: ",[160,563,564],{"class":305},"true",[160,566,541],{"class":202},[160,568,569,572,575,577,580],{"class":162,"line":225},[160,570,571],{"class":202},"  theme: toast.",[160,573,574],{"class":305},"THEME",[160,576,137],{"class":202},[160,578,579],{"class":305},"COLORED",[160,581,541],{"class":202},[160,583,584],{"class":162,"line":238},[160,585,587],{"class":586},"s9BHP","  \u002F\u002F and so on ...\n",[160,589,590,593,596,599],{"class":162,"line":251},[160,591,592],{"class":202},"} ",[160,594,595],{"class":166},"as",[160,597,598],{"class":275}," ToastOptions",[160,600,458],{"class":202},[160,602,603],{"class":162,"line":256},[160,604,194],{"emptyLinePlaceholder":193},[160,606,607],{"class":162,"line":266},[160,608,609],{"class":586},"\u002F\u002F display toasts\n",[160,611,612,614,617,619,622,624,627,630,632,634],{"class":162,"line":322},[160,613,522],{"class":166},[160,615,616],{"class":305}," toastId",[160,618,528],{"class":166},[160,620,621],{"class":259}," toast",[160,623,288],{"class":202},[160,625,626],{"class":170},"\"Hello\"",[160,628,629],{"class":202},", options ",[160,631,595],{"class":166},[160,633,598],{"class":275},[160,635,636],{"class":202},");\n",[160,638,639],{"class":162,"line":352},[160,640,194],{"emptyLinePlaceholder":193},[160,642,643],{"class":162,"line":377},[160,644,645],{"class":586},"\u002F\u002Fshortcut to different types\n",[160,647,648,651,654,656,658,660,662,664],{"class":162,"line":389},[160,649,650],{"class":202},"toast.",[160,652,653],{"class":259},"success",[160,655,288],{"class":202},[160,657,626],{"class":170},[160,659,629],{"class":202},[160,661,595],{"class":166},[160,663,598],{"class":275},[160,665,636],{"class":202},[160,667,668,670,673,675,678,680,682,684],{"class":162,"line":399},[160,669,650],{"class":202},[160,671,672],{"class":259},"info",[160,674,288],{"class":202},[160,676,677],{"class":170},"\"World\"",[160,679,629],{"class":202},[160,681,595],{"class":166},[160,683,598],{"class":275},[160,685,636],{"class":202},[160,687,688,690,693,696,698,700],{"class":162,"line":410},[160,689,650],{"class":202},[160,691,692],{"class":259},"warn",[160,694,695],{"class":202},"(MyComponent, options ",[160,697,595],{"class":166},[160,699,598],{"class":275},[160,701,636],{"class":202},[160,703,704,706,709,711,714,716,718,720],{"class":162,"line":416},[160,705,650],{"class":202},[160,707,708],{"class":259},"error",[160,710,288],{"class":202},[160,712,713],{"class":170},"\"Error\"",[160,715,629],{"class":202},[160,717,595],{"class":166},[160,719,598],{"class":275},[160,721,636],{"class":202},[12,723,724],{},"But we don't want to care about firing toasts in the frontend – just fire them whenever they pop in! Read on...",[103,726,728],{"id":727},"toastnotifications-vue-component","ToastNotifications Vue component",[12,730,731,732,735,736,739],{},"Let's now write our global ",[145,733,734],{},"ToastNotifications"," Vue component. First, create a composable ",[145,737,738],{},"resources\u002Fjs\u002FComposables\u002FToastNotifications.js"," with all the «business logic»:",[150,741,744],{"className":152,"code":742,"filename":743,"language":155,"meta":156,"style":156},"import { ref, watch } from 'vue'\nimport { usePage } from '@inertiajs\u002Fvue3'\nimport { toast } from 'vue3-toastify'\n\nconst toasts = ref()\n\nconst reToasted = ref(false)\n\nfunction fireToast(notification, sticky = false) {\n    toast(notification.message, {\n        toastId: notification.id,\n        type: notification.type,\n        newestOnTop: true,\n        theme: toast.THEME.COLORED,\n        autoClose: !sticky && (notification.type == 'success' ? 5000 : false),\n        closeOnClick: !sticky,\n        onClose: () => (reToasted.value = false),\n    })\n}\n\nfunction fireToasts(sticky = false) {\n    toasts.value?.forEach((notification) => fireToast(notification, sticky))\n}\n\nfunction toastAgain() {\n    reToasted.value ? toast.remove() : fireToasts(true)\n    reToasted.value = !reToasted.value\n}\n\nwatch(\n    \u002F\u002F NOTE: Since Inertia.js 1.0.1, usePage() may return null initially.\n    () => usePage()?.props?.flash.toasts,\n    (newToasts) => {\n        reToasted.value = false\n        toasts.value = newToasts\n        fireToasts()\n    }\n)\n\nexport function useToasts() {\n    return {\n        toasts,\n        toastAgain,\n        reToasted,\n    }\n}\n","ToastNotifications.js",[145,745,746,757,768,778,782,797,801,820,824,850,858,863,868,877,890,927,937,956,961,966,971,989,1012,1017,1022,1033,1062,1075,1080,1085,1094,1100,1114,1129,1140,1151,1159,1165,1170,1175,1189,1197,1203,1209,1215,1220],{"__ignoreMap":156},[160,747,748,750,753,755],{"class":162,"line":163},[160,749,167],{"class":166},[160,751,752],{"class":202}," { ref, watch } ",[160,754,206],{"class":166},[160,756,209],{"class":170},[160,758,759,761,764,766],{"class":162,"line":174},[160,760,167],{"class":166},[160,762,763],{"class":202}," { usePage } ",[160,765,206],{"class":166},[160,767,222],{"class":170},[160,769,770,772,774,776],{"class":162,"line":182},[160,771,167],{"class":166},[160,773,509],{"class":202},[160,775,206],{"class":166},[160,777,248],{"class":170},[160,779,780],{"class":162,"line":190},[160,781,194],{"emptyLinePlaceholder":193},[160,783,784,786,789,791,794],{"class":162,"line":197},[160,785,522],{"class":166},[160,787,788],{"class":305}," toasts",[160,790,528],{"class":166},[160,792,793],{"class":259}," ref",[160,795,796],{"class":202},"()\n",[160,798,799],{"class":162,"line":212},[160,800,194],{"emptyLinePlaceholder":193},[160,802,803,805,808,810,812,814,817],{"class":162,"line":225},[160,804,522],{"class":166},[160,806,807],{"class":305}," reToasted",[160,809,528],{"class":166},[160,811,793],{"class":259},[160,813,288],{"class":202},[160,815,816],{"class":305},"false",[160,818,819],{"class":202},")\n",[160,821,822],{"class":162,"line":238},[160,823,194],{"emptyLinePlaceholder":193},[160,825,826,829,832,834,837,839,842,844,847],{"class":162,"line":251},[160,827,828],{"class":166},"function",[160,830,831],{"class":259}," fireToast",[160,833,288],{"class":202},[160,835,836],{"class":275},"notification",[160,838,115],{"class":202},[160,840,841],{"class":275},"sticky",[160,843,528],{"class":166},[160,845,846],{"class":305}," false",[160,848,849],{"class":202},") {\n",[160,851,852,855],{"class":162,"line":256},[160,853,854],{"class":259},"    toast",[160,856,857],{"class":202},"(notification.message, {\n",[160,859,860],{"class":162,"line":266},[160,861,862],{"class":202},"        toastId: notification.id,\n",[160,864,865],{"class":162,"line":322},[160,866,867],{"class":202},"        type: notification.type,\n",[160,869,870,873,875],{"class":162,"line":352},[160,871,872],{"class":202},"        newestOnTop: ",[160,874,564],{"class":305},[160,876,541],{"class":202},[160,878,879,882,884,886,888],{"class":162,"line":377},[160,880,881],{"class":202},"        theme: toast.",[160,883,574],{"class":305},[160,885,137],{"class":202},[160,887,579],{"class":305},[160,889,541],{"class":202},[160,891,892,895,898,901,904,907,910,913,916,919,922,924],{"class":162,"line":389},[160,893,894],{"class":202},"        autoClose: ",[160,896,897],{"class":166},"!",[160,899,900],{"class":202},"sticky ",[160,902,903],{"class":166},"&&",[160,905,906],{"class":202}," (notification.type ",[160,908,909],{"class":166},"==",[160,911,912],{"class":170}," 'success'",[160,914,915],{"class":166}," ?",[160,917,918],{"class":305}," 5000",[160,920,921],{"class":166}," :",[160,923,846],{"class":305},[160,925,926],{"class":202},"),\n",[160,928,929,932,934],{"class":162,"line":399},[160,930,931],{"class":202},"        closeOnClick: ",[160,933,897],{"class":166},[160,935,936],{"class":202},"sticky,\n",[160,938,939,942,944,946,949,952,954],{"class":162,"line":410},[160,940,941],{"class":259},"        onClose",[160,943,366],{"class":202},[160,945,282],{"class":166},[160,947,948],{"class":202}," (reToasted.value ",[160,950,951],{"class":166},"=",[160,953,846],{"class":305},[160,955,926],{"class":202},[160,957,958],{"class":162,"line":416},[160,959,960],{"class":202},"    })\n",[160,962,964],{"class":162,"line":963},19,[160,965,475],{"class":202},[160,967,969],{"class":162,"line":968},20,[160,970,194],{"emptyLinePlaceholder":193},[160,972,974,976,979,981,983,985,987],{"class":162,"line":973},21,[160,975,828],{"class":166},[160,977,978],{"class":259}," fireToasts",[160,980,288],{"class":202},[160,982,841],{"class":275},[160,984,528],{"class":166},[160,986,846],{"class":305},[160,988,849],{"class":202},[160,990,992,995,998,1001,1003,1005,1007,1009],{"class":162,"line":991},22,[160,993,994],{"class":202},"    toasts.value?.",[160,996,997],{"class":259},"forEach",[160,999,1000],{"class":202},"((",[160,1002,836],{"class":275},[160,1004,279],{"class":202},[160,1006,282],{"class":166},[160,1008,831],{"class":259},[160,1010,1011],{"class":202},"(notification, sticky))\n",[160,1013,1015],{"class":162,"line":1014},23,[160,1016,475],{"class":202},[160,1018,1020],{"class":162,"line":1019},24,[160,1021,194],{"emptyLinePlaceholder":193},[160,1023,1025,1027,1030],{"class":162,"line":1024},25,[160,1026,828],{"class":166},[160,1028,1029],{"class":259}," toastAgain",[160,1031,1032],{"class":202},"() {\n",[160,1034,1036,1039,1042,1045,1048,1051,1054,1056,1058,1060],{"class":162,"line":1035},26,[160,1037,1038],{"class":202},"    reToasted.value ",[160,1040,1041],{"class":166},"?",[160,1043,1044],{"class":202}," toast.",[160,1046,1047],{"class":259},"remove",[160,1049,1050],{"class":202},"() ",[160,1052,1053],{"class":166},":",[160,1055,978],{"class":259},[160,1057,288],{"class":202},[160,1059,564],{"class":305},[160,1061,819],{"class":202},[160,1063,1065,1067,1069,1072],{"class":162,"line":1064},27,[160,1066,1038],{"class":202},[160,1068,951],{"class":166},[160,1070,1071],{"class":166}," !",[160,1073,1074],{"class":202},"reToasted.value\n",[160,1076,1078],{"class":162,"line":1077},28,[160,1079,475],{"class":202},[160,1081,1083],{"class":162,"line":1082},29,[160,1084,194],{"emptyLinePlaceholder":193},[160,1086,1088,1091],{"class":162,"line":1087},30,[160,1089,1090],{"class":259},"watch",[160,1092,1093],{"class":202},"(\n",[160,1095,1097],{"class":162,"line":1096},31,[160,1098,1099],{"class":586},"    \u002F\u002F NOTE: Since Inertia.js 1.0.1, usePage() may return null initially.\n",[160,1101,1103,1106,1108,1111],{"class":162,"line":1102},32,[160,1104,1105],{"class":202},"    () ",[160,1107,282],{"class":166},[160,1109,1110],{"class":259}," usePage",[160,1112,1113],{"class":202},"()?.props?.flash.toasts,\n",[160,1115,1117,1120,1123,1125,1127],{"class":162,"line":1116},33,[160,1118,1119],{"class":202},"    (",[160,1121,1122],{"class":275},"newToasts",[160,1124,279],{"class":202},[160,1126,282],{"class":166},[160,1128,441],{"class":202},[160,1130,1132,1135,1137],{"class":162,"line":1131},34,[160,1133,1134],{"class":202},"        reToasted.value ",[160,1136,951],{"class":166},[160,1138,1139],{"class":305}," false\n",[160,1141,1143,1146,1148],{"class":162,"line":1142},35,[160,1144,1145],{"class":202},"        toasts.value ",[160,1147,951],{"class":166},[160,1149,1150],{"class":202}," newToasts\n",[160,1152,1154,1157],{"class":162,"line":1153},36,[160,1155,1156],{"class":259},"        fireToasts",[160,1158,796],{"class":202},[160,1160,1162],{"class":162,"line":1161},37,[160,1163,1164],{"class":202},"    }\n",[160,1166,1168],{"class":162,"line":1167},38,[160,1169,819],{"class":202},[160,1171,1173],{"class":162,"line":1172},39,[160,1174,194],{"emptyLinePlaceholder":193},[160,1176,1178,1181,1184,1187],{"class":162,"line":1177},40,[160,1179,1180],{"class":166},"export",[160,1182,1183],{"class":166}," function",[160,1185,1186],{"class":259}," useToasts",[160,1188,1032],{"class":202},[160,1190,1192,1195],{"class":162,"line":1191},41,[160,1193,1194],{"class":166},"    return",[160,1196,441],{"class":202},[160,1198,1200],{"class":162,"line":1199},42,[160,1201,1202],{"class":202},"        toasts,\n",[160,1204,1206],{"class":162,"line":1205},43,[160,1207,1208],{"class":202},"        toastAgain,\n",[160,1210,1212],{"class":162,"line":1211},44,[160,1213,1214],{"class":202},"        reToasted,\n",[160,1216,1218],{"class":162,"line":1217},45,[160,1219,1164],{"class":202},[160,1221,1223],{"class":162,"line":1222},46,[160,1224,475],{"class":202},[12,1226,1227,1228,1231,1232,1235],{},"This fires toast messages whenever the ",[145,1229,1230],{},"flash.toasts"," shared prop gets filled. To make sure we don't ever create duplicate toasts, let's give each toast a unique id. Whenever the watched ",[145,1233,1234],{},"usePage().props.flash.toasts"," changes, the new toasts get fired.",[12,1237,1238,1239,1242,1243,1246,1247,1250],{},"I am using the following helpers in ",[145,1240,1241],{},"bootstrap\u002Fhelpers.php"," (loaded in ",[145,1244,1245],{},"composer.json","'s ",[145,1248,1249],{},"\"autoload\": { \"files\": [ \"bootstrap\u002Fhelpers.php\" ], }"," where the toasts are getting added to the session:",[150,1252,1257],{"className":1253,"code":1254,"filename":1255,"language":1256,"meta":156,"style":156},"language-php shiki shiki-themes github-light-default github-light-default github-dark-default","if (! function_exists('toast')) {\n    function toast(ToastType $type, string $message, ?RedirectResponse $response = null)\n    {\n        $toasts = session()->get('toasts', []);\n        $toasts[] = [\n            'id'      => Str::uuid(),\n            'type'    => $type->value,\n            'message' => $message,\n        ];\n        if ($response) {\n            return  $response->with('toasts', $toasts);\n        } else {\n            session()->flash('toasts', $toasts);\n        }\n    }\n}\n\nif (! function_exists('toast_success')) {\n    function toast_success(string $message)\n    {\n        return toast(ToastType::SUCCESS, $message);\n    }\n}\n\nif (! function_exists('toast_warning')) {\n    function toast_warning(string $message)\n    {\n        return toast(ToastType::WARNING, $message);\n    }\n}\n\nif (! function_exists('toast_error')) {\n    function toast_error(string $message)\n    {\n        return toast(ToastType::ERROR, $message);\n    }\n}\n","helpers.php","php",[145,1258,1259,1280,1316,1321,1348,1358,1378,1394,1405,1410,1418,1438,1448,1466,1471,1475,1479,1483,1500,1514,1518,1535,1539,1543,1547,1564,1577,1581,1598,1602,1606,1610,1627,1640,1644,1661,1665],{"__ignoreMap":156},[160,1260,1261,1264,1267,1269,1272,1274,1277],{"class":162,"line":163},[160,1262,1263],{"class":166},"if",[160,1265,1266],{"class":202}," (",[160,1268,897],{"class":166},[160,1270,1271],{"class":305}," function_exists",[160,1273,288],{"class":202},[160,1275,1276],{"class":170},"'toast'",[160,1278,1279],{"class":202},")) {\n",[160,1281,1282,1285,1287,1289,1292,1295,1298,1301,1303,1306,1309,1311,1314],{"class":162,"line":174},[160,1283,1284],{"class":166},"    function",[160,1286,621],{"class":259},[160,1288,288],{"class":202},[160,1290,1291],{"class":305},"ToastType",[160,1293,1294],{"class":202}," $type, ",[160,1296,1297],{"class":166},"string",[160,1299,1300],{"class":202}," $message, ",[160,1302,1041],{"class":166},[160,1304,1305],{"class":305},"RedirectResponse",[160,1307,1308],{"class":202}," $response ",[160,1310,951],{"class":166},[160,1312,1313],{"class":305}," null",[160,1315,819],{"class":202},[160,1317,1318],{"class":162,"line":182},[160,1319,1320],{"class":202},"    {\n",[160,1322,1323,1326,1328,1331,1334,1337,1340,1342,1345],{"class":162,"line":190},[160,1324,1325],{"class":202},"        $toasts ",[160,1327,951],{"class":166},[160,1329,1330],{"class":259}," session",[160,1332,1333],{"class":202},"()",[160,1335,1336],{"class":166},"->",[160,1338,1339],{"class":259},"get",[160,1341,288],{"class":202},[160,1343,1344],{"class":170},"'toasts'",[160,1346,1347],{"class":202},", []);\n",[160,1349,1350,1353,1355],{"class":162,"line":197},[160,1351,1352],{"class":202},"        $toasts[] ",[160,1354,951],{"class":166},[160,1356,1357],{"class":202}," [\n",[160,1359,1360,1363,1366,1369,1372,1375],{"class":162,"line":212},[160,1361,1362],{"class":170},"            'id'",[160,1364,1365],{"class":166},"      =>",[160,1367,1368],{"class":305}," Str",[160,1370,1371],{"class":166},"::",[160,1373,1374],{"class":259},"uuid",[160,1376,1377],{"class":202},"(),\n",[160,1379,1380,1383,1386,1389,1391],{"class":162,"line":225},[160,1381,1382],{"class":170},"            'type'",[160,1384,1385],{"class":166},"    =>",[160,1387,1388],{"class":202}," $type",[160,1390,1336],{"class":166},[160,1392,1393],{"class":202},"value,\n",[160,1395,1396,1399,1402],{"class":162,"line":238},[160,1397,1398],{"class":170},"            'message'",[160,1400,1401],{"class":166}," =>",[160,1403,1404],{"class":202}," $message,\n",[160,1406,1407],{"class":162,"line":251},[160,1408,1409],{"class":202},"        ];\n",[160,1411,1412,1415],{"class":162,"line":256},[160,1413,1414],{"class":166},"        if",[160,1416,1417],{"class":202}," ($response) {\n",[160,1419,1420,1423,1426,1428,1431,1433,1435],{"class":162,"line":266},[160,1421,1422],{"class":166},"            return",[160,1424,1425],{"class":202},"  $response",[160,1427,1336],{"class":166},[160,1429,1430],{"class":259},"with",[160,1432,288],{"class":202},[160,1434,1344],{"class":170},[160,1436,1437],{"class":202},", $toasts);\n",[160,1439,1440,1443,1446],{"class":162,"line":322},[160,1441,1442],{"class":202},"        } ",[160,1444,1445],{"class":166},"else",[160,1447,441],{"class":202},[160,1449,1450,1453,1455,1457,1460,1462,1464],{"class":162,"line":352},[160,1451,1452],{"class":259},"            session",[160,1454,1333],{"class":202},[160,1456,1336],{"class":166},[160,1458,1459],{"class":259},"flash",[160,1461,288],{"class":202},[160,1463,1344],{"class":170},[160,1465,1437],{"class":202},[160,1467,1468],{"class":162,"line":377},[160,1469,1470],{"class":202},"        }\n",[160,1472,1473],{"class":162,"line":389},[160,1474,1164],{"class":202},[160,1476,1477],{"class":162,"line":399},[160,1478,475],{"class":202},[160,1480,1481],{"class":162,"line":410},[160,1482,194],{"emptyLinePlaceholder":193},[160,1484,1485,1487,1489,1491,1493,1495,1498],{"class":162,"line":416},[160,1486,1263],{"class":166},[160,1488,1266],{"class":202},[160,1490,897],{"class":166},[160,1492,1271],{"class":305},[160,1494,288],{"class":202},[160,1496,1497],{"class":170},"'toast_success'",[160,1499,1279],{"class":202},[160,1501,1502,1504,1507,1509,1511],{"class":162,"line":963},[160,1503,1284],{"class":166},[160,1505,1506],{"class":259}," toast_success",[160,1508,288],{"class":202},[160,1510,1297],{"class":166},[160,1512,1513],{"class":202}," $message)\n",[160,1515,1516],{"class":162,"line":968},[160,1517,1320],{"class":202},[160,1519,1520,1522,1524,1526,1528,1530,1532],{"class":162,"line":973},[160,1521,355],{"class":166},[160,1523,621],{"class":259},[160,1525,288],{"class":202},[160,1527,1291],{"class":305},[160,1529,1371],{"class":166},[160,1531,554],{"class":305},[160,1533,1534],{"class":202},", $message);\n",[160,1536,1537],{"class":162,"line":991},[160,1538,1164],{"class":202},[160,1540,1541],{"class":162,"line":1014},[160,1542,475],{"class":202},[160,1544,1545],{"class":162,"line":1019},[160,1546,194],{"emptyLinePlaceholder":193},[160,1548,1549,1551,1553,1555,1557,1559,1562],{"class":162,"line":1024},[160,1550,1263],{"class":166},[160,1552,1266],{"class":202},[160,1554,897],{"class":166},[160,1556,1271],{"class":305},[160,1558,288],{"class":202},[160,1560,1561],{"class":170},"'toast_warning'",[160,1563,1279],{"class":202},[160,1565,1566,1568,1571,1573,1575],{"class":162,"line":1035},[160,1567,1284],{"class":166},[160,1569,1570],{"class":259}," toast_warning",[160,1572,288],{"class":202},[160,1574,1297],{"class":166},[160,1576,1513],{"class":202},[160,1578,1579],{"class":162,"line":1064},[160,1580,1320],{"class":202},[160,1582,1583,1585,1587,1589,1591,1593,1596],{"class":162,"line":1077},[160,1584,355],{"class":166},[160,1586,621],{"class":259},[160,1588,288],{"class":202},[160,1590,1291],{"class":305},[160,1592,1371],{"class":166},[160,1594,1595],{"class":305},"WARNING",[160,1597,1534],{"class":202},[160,1599,1600],{"class":162,"line":1082},[160,1601,1164],{"class":202},[160,1603,1604],{"class":162,"line":1087},[160,1605,475],{"class":202},[160,1607,1608],{"class":162,"line":1096},[160,1609,194],{"emptyLinePlaceholder":193},[160,1611,1612,1614,1616,1618,1620,1622,1625],{"class":162,"line":1102},[160,1613,1263],{"class":166},[160,1615,1266],{"class":202},[160,1617,897],{"class":166},[160,1619,1271],{"class":305},[160,1621,288],{"class":202},[160,1623,1624],{"class":170},"'toast_error'",[160,1626,1279],{"class":202},[160,1628,1629,1631,1634,1636,1638],{"class":162,"line":1116},[160,1630,1284],{"class":166},[160,1632,1633],{"class":259}," toast_error",[160,1635,288],{"class":202},[160,1637,1297],{"class":166},[160,1639,1513],{"class":202},[160,1641,1642],{"class":162,"line":1131},[160,1643,1320],{"class":202},[160,1645,1646,1648,1650,1652,1654,1656,1659],{"class":162,"line":1142},[160,1647,355],{"class":166},[160,1649,621],{"class":259},[160,1651,288],{"class":202},[160,1653,1291],{"class":305},[160,1655,1371],{"class":166},[160,1657,1658],{"class":305},"ERROR",[160,1660,1534],{"class":202},[160,1662,1663],{"class":162,"line":1153},[160,1664,1164],{"class":202},[160,1666,1667],{"class":162,"line":1161},[160,1668,475],{"class":202},[12,1670,1671],{},"... and the related PHP enum – completely unnecessary but I like to favor enums over strings wherever I can:",[150,1673,1676],{"className":1253,"code":1674,"filename":1675,"language":1256,"meta":156,"style":156},"namespace App\\Enums;\n\nenum ToastType: string\n{\n    case SUCCESS = 'success';\n    case WARNING = 'warning';\n    case ERROR = 'error';\n}\n","ToastType.php",[145,1677,1678,1688,1692,1705,1710,1724,1738,1752],{"__ignoreMap":156},[160,1679,1680,1683,1686],{"class":162,"line":163},[160,1681,1682],{"class":166},"namespace",[160,1684,1685],{"class":275}," App\\Enums",[160,1687,458],{"class":202},[160,1689,1690],{"class":162,"line":174},[160,1691,194],{"emptyLinePlaceholder":193},[160,1693,1694,1697,1700,1702],{"class":162,"line":182},[160,1695,1696],{"class":166},"enum",[160,1698,1699],{"class":275}," ToastType",[160,1701,1053],{"class":166},[160,1703,1704],{"class":166}," string\n",[160,1706,1707],{"class":162,"line":190},[160,1708,1709],{"class":202},"{\n",[160,1711,1712,1715,1718,1720,1722],{"class":162,"line":197},[160,1713,1714],{"class":166},"    case",[160,1716,1717],{"class":305}," SUCCESS",[160,1719,528],{"class":166},[160,1721,912],{"class":170},[160,1723,458],{"class":202},[160,1725,1726,1728,1731,1733,1736],{"class":162,"line":212},[160,1727,1714],{"class":166},[160,1729,1730],{"class":305}," WARNING",[160,1732,528],{"class":166},[160,1734,1735],{"class":170}," 'warning'",[160,1737,458],{"class":202},[160,1739,1740,1742,1745,1747,1750],{"class":162,"line":225},[160,1741,1714],{"class":166},[160,1743,1744],{"class":305}," ERROR",[160,1746,528],{"class":166},[160,1748,1749],{"class":170}," 'error'",[160,1751,458],{"class":202},[160,1753,1754],{"class":162,"line":238},[160,1755,475],{"class":202},[12,1757,1758,1759,1764,1765,1768],{},"Now, to make the toasts available to your frontend, add them to the ",[19,1760,1763],{"href":1761,"rel":1762},"https:\u002F\u002Finertiajs.com\u002Fshared-data",[23],"Inertia shared data"," in ",[145,1766,1767],{},"HandleInertiaRequests"," middleware:",[150,1770,1773],{"className":1253,"code":1771,"filename":1772,"language":1256,"meta":156,"style":156},"\u003C?php\n\nnamespace App\\Http\\Middleware;\n\nuse Inertia\\Middleware;\n\nclass HandleInertiaRequests extends Middleware\n{\n    public function share(Request $request)\n    {\n        return array_merge(parent::share($request), [\n            'flash' => fn () => [\n                'toasts'=> $request->session()->get('toasts'),\n            ],\n            \u002F\u002F ...\n        ]);\n    }\n}\n","HandleInertiaRequests.php",[145,1774,1775,1783,1787,1796,1800,1809,1813,1827,1831,1849,1853,1871,1884,1911,1916,1921,1926,1930],{"__ignoreMap":156},[160,1776,1777,1780],{"class":162,"line":163},[160,1778,1779],{"class":166},"\u003C?",[160,1781,1782],{"class":305},"php\n",[160,1784,1785],{"class":162,"line":174},[160,1786,194],{"emptyLinePlaceholder":193},[160,1788,1789,1791,1794],{"class":162,"line":182},[160,1790,1682],{"class":166},[160,1792,1793],{"class":275}," App\\Http\\Middleware",[160,1795,458],{"class":202},[160,1797,1798],{"class":162,"line":190},[160,1799,194],{"emptyLinePlaceholder":193},[160,1801,1802,1804,1807],{"class":162,"line":197},[160,1803,383],{"class":166},[160,1805,1806],{"class":305}," Inertia\\Middleware",[160,1808,458],{"class":202},[160,1810,1811],{"class":162,"line":212},[160,1812,194],{"emptyLinePlaceholder":193},[160,1814,1815,1818,1821,1824],{"class":162,"line":225},[160,1816,1817],{"class":166},"class",[160,1819,1820],{"class":275}," HandleInertiaRequests",[160,1822,1823],{"class":166}," extends",[160,1825,1826],{"class":305}," Middleware\n",[160,1828,1829],{"class":162,"line":238},[160,1830,1709],{"class":202},[160,1832,1833,1836,1838,1841,1843,1846],{"class":162,"line":251},[160,1834,1835],{"class":166},"    public",[160,1837,1183],{"class":166},[160,1839,1840],{"class":259}," share",[160,1842,288],{"class":202},[160,1844,1845],{"class":305},"Request",[160,1847,1848],{"class":202}," $request)\n",[160,1850,1851],{"class":162,"line":256},[160,1852,1320],{"class":202},[160,1854,1855,1857,1860,1862,1865,1868],{"class":162,"line":266},[160,1856,355],{"class":166},[160,1858,1859],{"class":305}," array_merge",[160,1861,288],{"class":202},[160,1863,1864],{"class":166},"parent::",[160,1866,1867],{"class":259},"share",[160,1869,1870],{"class":202},"($request), [\n",[160,1872,1873,1876,1878,1881],{"class":162,"line":322},[160,1874,1875],{"class":170},"            'flash'",[160,1877,1401],{"class":166},[160,1879,1880],{"class":166}," fn",[160,1882,1883],{"class":202}," () => [\n",[160,1885,1886,1889,1891,1894,1896,1899,1901,1903,1905,1907,1909],{"class":162,"line":352},[160,1887,1888],{"class":170},"                'toasts'",[160,1890,282],{"class":166},[160,1892,1893],{"class":202}," $request",[160,1895,1336],{"class":166},[160,1897,1898],{"class":259},"session",[160,1900,1333],{"class":202},[160,1902,1336],{"class":166},[160,1904,1339],{"class":259},[160,1906,288],{"class":202},[160,1908,1344],{"class":170},[160,1910,926],{"class":202},[160,1912,1913],{"class":162,"line":377},[160,1914,1915],{"class":202},"            ],\n",[160,1917,1918],{"class":162,"line":389},[160,1919,1920],{"class":586},"            \u002F\u002F ...\n",[160,1922,1923],{"class":162,"line":399},[160,1924,1925],{"class":202},"        ]);\n",[160,1927,1928],{"class":162,"line":410},[160,1929,1164],{"class":202},[160,1931,1932],{"class":162,"line":416},[160,1933,475],{"class":202},[12,1935,1936,1937,1939],{},"And finally, build your ",[145,1938,734],{}," Vue component:",[150,1941,1946],{"className":1942,"code":1943,"filename":1944,"language":1945,"meta":156,"style":156},"language-vue shiki shiki-themes github-light-default github-light-default github-dark-default","\u003Cscript setup>\nimport { BellAlertIcon, BellSlashIcon } from '@heroicons\u002Fvue\u002F24\u002Foutline'\nimport { useToasts } from '@\u002FComposables\u002FToastNotifications'\n\nconst { toasts, toastAgain, reToasted } = useToasts()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n    \u003Cdiv>\n        \u003Cbutton\n            v-if=\"toasts\"\n            class=\"flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 hover:bg-gray-800 hover:text-white dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white\"\n            :class=\"{ 'animate-pulse': !reToasted }\"\n            @click=\"toastAgain()\"\n        >\n            \u003Ccomponent :is=\"reToasted ? 'BellSlashIcon' : 'BellAlertIcon'\" class=\"h-5 w-5\" \u002F>\n        \u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n","ToastNotifications.vue","vue",[145,1947,1948,1963,1975,1987,1991,2020,2029,2033,2042,2052,2060,2070,2080,2090,2100,2105,2132,2142,2151],{"__ignoreMap":156},[160,1949,1950,1953,1957,1960],{"class":162,"line":163},[160,1951,1952],{"class":202},"\u003C",[160,1954,1956],{"class":1955},"sfEsd","script",[160,1958,1959],{"class":305}," setup",[160,1961,1962],{"class":202},">\n",[160,1964,1965,1967,1970,1972],{"class":162,"line":174},[160,1966,167],{"class":166},[160,1968,1969],{"class":202}," { BellAlertIcon, BellSlashIcon } ",[160,1971,206],{"class":166},[160,1973,1974],{"class":170}," '@heroicons\u002Fvue\u002F24\u002Foutline'\n",[160,1976,1977,1979,1982,1984],{"class":162,"line":182},[160,1978,167],{"class":166},[160,1980,1981],{"class":202}," { useToasts } ",[160,1983,206],{"class":166},[160,1985,1986],{"class":170}," '@\u002FComposables\u002FToastNotifications'\n",[160,1988,1989],{"class":162,"line":190},[160,1990,194],{"emptyLinePlaceholder":193},[160,1992,1993,1995,1998,2001,2003,2006,2008,2011,2014,2016,2018],{"class":162,"line":197},[160,1994,522],{"class":166},[160,1996,1997],{"class":202}," { ",[160,1999,2000],{"class":305},"toasts",[160,2002,115],{"class":202},[160,2004,2005],{"class":305},"toastAgain",[160,2007,115],{"class":202},[160,2009,2010],{"class":305},"reToasted",[160,2012,2013],{"class":202}," } ",[160,2015,951],{"class":166},[160,2017,1186],{"class":259},[160,2019,796],{"class":202},[160,2021,2022,2025,2027],{"class":162,"line":212},[160,2023,2024],{"class":202},"\u003C\u002F",[160,2026,1956],{"class":1955},[160,2028,1962],{"class":202},[160,2030,2031],{"class":162,"line":225},[160,2032,194],{"emptyLinePlaceholder":193},[160,2034,2035,2037,2040],{"class":162,"line":238},[160,2036,1952],{"class":202},[160,2038,2039],{"class":1955},"template",[160,2041,1962],{"class":202},[160,2043,2044,2047,2050],{"class":162,"line":251},[160,2045,2046],{"class":202},"    \u003C",[160,2048,2049],{"class":1955},"div",[160,2051,1962],{"class":202},[160,2053,2054,2057],{"class":162,"line":256},[160,2055,2056],{"class":202},"        \u003C",[160,2058,2059],{"class":1955},"button\n",[160,2061,2062,2065,2067],{"class":162,"line":266},[160,2063,2064],{"class":305},"            v-if",[160,2066,951],{"class":202},[160,2068,2069],{"class":170},"\"toasts\"\n",[160,2071,2072,2075,2077],{"class":162,"line":322},[160,2073,2074],{"class":305},"            class",[160,2076,951],{"class":202},[160,2078,2079],{"class":170},"\"flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 hover:bg-gray-800 hover:text-white dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white\"\n",[160,2081,2082,2085,2087],{"class":162,"line":352},[160,2083,2084],{"class":305},"            :class",[160,2086,951],{"class":202},[160,2088,2089],{"class":170},"\"{ 'animate-pulse': !reToasted }\"\n",[160,2091,2092,2095,2097],{"class":162,"line":377},[160,2093,2094],{"class":305},"            @click",[160,2096,951],{"class":202},[160,2098,2099],{"class":170},"\"toastAgain()\"\n",[160,2101,2102],{"class":162,"line":389},[160,2103,2104],{"class":202},"        >\n",[160,2106,2107,2110,2113,2116,2118,2121,2124,2126,2129],{"class":162,"line":399},[160,2108,2109],{"class":202},"            \u003C",[160,2111,2112],{"class":1955},"component",[160,2114,2115],{"class":305}," :is",[160,2117,951],{"class":202},[160,2119,2120],{"class":170},"\"reToasted ? 'BellSlashIcon' : 'BellAlertIcon'\"",[160,2122,2123],{"class":305}," class",[160,2125,951],{"class":202},[160,2127,2128],{"class":170},"\"h-5 w-5\"",[160,2130,2131],{"class":202}," \u002F>\n",[160,2133,2134,2137,2140],{"class":162,"line":410},[160,2135,2136],{"class":202},"        \u003C\u002F",[160,2138,2139],{"class":1955},"button",[160,2141,1962],{"class":202},[160,2143,2144,2147,2149],{"class":162,"line":416},[160,2145,2146],{"class":202},"    \u003C\u002F",[160,2148,2049],{"class":1955},[160,2150,1962],{"class":202},[160,2152,2153,2155,2157],{"class":162,"line":963},[160,2154,2024],{"class":202},[160,2156,2039],{"class":1955},[160,2158,1962],{"class":202},[12,2160,2161,2162,2165],{},"You don't need to get that fancy and could also just load the toasts somewhere else without an extra Vue component, or at least without the ",[145,2163,2164],{},"\u003Ctemplate>"," part. But this component provides you the following:",[45,2167,2168,2171,2178,2181],{},[48,2169,2170],{},"Shows nothing when there is no toast message",[48,2172,2173,2174,2177],{},"Shows you a nice ",[145,2175,2176],{},"BellAlertIcon"," button when there are any toasts available (open or already closed but still on the same page)",[48,2179,2180],{},"You can click on the bell-alert icon to re-open the previous messages again.",[48,2182,2183,2184,2186,2187,2189,2190,2193],{},"When toasts are re-opened, they are not auto-closed (see ",[145,2185,841],{}," flag in ",[145,2188,743],{}," function ",[145,2191,2192],{},"fireToast()","), but for easy closing of all toasts, you can just click on the bell-slash icon instead of closing each toast message individually.",[12,2195,2196],{},"Just put this component into your app header or main layout:",[150,2198,2200],{"className":1942,"code":2199,"language":1945,"meta":156,"style":156},"\u003Ctemplate>\n    \u003C!-- ... -->\n    \u003CToastNotifications \u002F>\n",[145,2201,2202,2210,2215],{"__ignoreMap":156},[160,2203,2204,2206,2208],{"class":162,"line":163},[160,2205,1952],{"class":202},[160,2207,2039],{"class":1955},[160,2209,1962],{"class":202},[160,2211,2212],{"class":162,"line":174},[160,2213,2214],{"class":586},"    \u003C!-- ... -->\n",[160,2216,2217,2219,2221],{"class":162,"line":182},[160,2218,2046],{"class":202},[160,2220,734],{"class":1955},[160,2222,2131],{"class":202},[12,2224,2225],{},"done. 🎉",[97,2227,2228],{},[12,2229,2230,2231,897],{},"Oh, and in case you're missing some import statements in my Vue code, I love on-demand component auto-importing with ",[19,2232,2235],{"href":2233,"rel":2234},"https:\u002F\u002Fgithub.com\u002Fantfu\u002Funplugin-vue-components",[23],"unplugin-vue-components",[103,2237,2239],{"id":2238},"usage-in-your-controllers","Usage in your Controllers",[12,2241,2242],{},"In your backend controllers, you can now simply use:",[150,2244,2246],{"className":1253,"code":2245,"language":1256,"meta":156,"style":156},"toast_success('User successfully updated!');\n",[145,2247,2248],{"__ignoreMap":156},[160,2249,2250,2253,2255,2258],{"class":162,"line":163},[160,2251,2252],{"class":259},"toast_success",[160,2254,288],{"class":202},[160,2256,2257],{"class":170},"'User successfully updated!'",[160,2259,636],{"class":202},[12,2261,2262,2263,2265,2266,2269],{},"Or how about extending the ",[145,2264,1305],{}," in your ",[145,2267,2268],{},"AppServiceProvider.php","?:",[150,2271,2273],{"className":1253,"code":2272,"filename":2268,"language":1256,"meta":156,"style":156},"class AppServiceProvider extends ServiceProvider\n{\n    \u002F\u002F ...\n    private function registerMacros()\n    {\n        RedirectResponse::macro(\n            'withSuccess',\n            fn (string $message) => toast(ToastType::SUCCESS, $message, $this)\n        );\n\n        RedirectResponse::macro(\n            'withError',\n            fn (string $message) => toast(ToastType::ERROR, $message, $this)\n        );\n    }\n",[145,2274,2275,2287,2291,2296,2308,2312,2324,2331,2362,2367,2371,2381,2388,2414,2418],{"__ignoreMap":156},[160,2276,2277,2279,2282,2284],{"class":162,"line":163},[160,2278,1817],{"class":166},[160,2280,2281],{"class":275}," AppServiceProvider",[160,2283,1823],{"class":166},[160,2285,2286],{"class":305}," ServiceProvider\n",[160,2288,2289],{"class":162,"line":174},[160,2290,1709],{"class":202},[160,2292,2293],{"class":162,"line":182},[160,2294,2295],{"class":586},"    \u002F\u002F ...\n",[160,2297,2298,2301,2303,2306],{"class":162,"line":190},[160,2299,2300],{"class":166},"    private",[160,2302,1183],{"class":166},[160,2304,2305],{"class":259}," registerMacros",[160,2307,796],{"class":202},[160,2309,2310],{"class":162,"line":197},[160,2311,1320],{"class":202},[160,2313,2314,2317,2319,2322],{"class":162,"line":212},[160,2315,2316],{"class":305},"        RedirectResponse",[160,2318,1371],{"class":166},[160,2320,2321],{"class":259},"macro",[160,2323,1093],{"class":202},[160,2325,2326,2329],{"class":162,"line":225},[160,2327,2328],{"class":170},"            'withSuccess'",[160,2330,541],{"class":202},[160,2332,2333,2336,2338,2340,2343,2346,2348,2350,2352,2354,2357,2360],{"class":162,"line":238},[160,2334,2335],{"class":166},"            fn",[160,2337,1266],{"class":202},[160,2339,1297],{"class":166},[160,2341,2342],{"class":202}," $message) => ",[160,2344,2345],{"class":259},"toast",[160,2347,288],{"class":202},[160,2349,1291],{"class":305},[160,2351,1371],{"class":166},[160,2353,554],{"class":305},[160,2355,2356],{"class":202},", $message, ",[160,2358,2359],{"class":305},"$this",[160,2361,819],{"class":202},[160,2363,2364],{"class":162,"line":251},[160,2365,2366],{"class":202},"        );\n",[160,2368,2369],{"class":162,"line":256},[160,2370,194],{"emptyLinePlaceholder":193},[160,2372,2373,2375,2377,2379],{"class":162,"line":266},[160,2374,2316],{"class":305},[160,2376,1371],{"class":166},[160,2378,2321],{"class":259},[160,2380,1093],{"class":202},[160,2382,2383,2386],{"class":162,"line":322},[160,2384,2385],{"class":170},"            'withError'",[160,2387,541],{"class":202},[160,2389,2390,2392,2394,2396,2398,2400,2402,2404,2406,2408,2410,2412],{"class":162,"line":352},[160,2391,2335],{"class":166},[160,2393,1266],{"class":202},[160,2395,1297],{"class":166},[160,2397,2342],{"class":202},[160,2399,2345],{"class":259},[160,2401,288],{"class":202},[160,2403,1291],{"class":305},[160,2405,1371],{"class":166},[160,2407,1658],{"class":305},[160,2409,2356],{"class":202},[160,2411,2359],{"class":305},[160,2413,819],{"class":202},[160,2415,2416],{"class":162,"line":377},[160,2417,2366],{"class":202},[160,2419,2420],{"class":162,"line":389},[160,2421,1164],{"class":202},[12,2423,2424],{},"Like this, you could just append the message to the redirect response:",[150,2426,2428],{"className":1253,"code":2427,"language":1256,"meta":156,"style":156},"    public function update(UpdateCustomerRequest $request, Customer $customer)\n    {\n        $customer->update($request->validated());\n        return back()->withSuccess('The customer was fully pimped.');\n    }\n",[145,2429,2430,2453,2457,2478,2499],{"__ignoreMap":156},[160,2431,2432,2434,2436,2439,2441,2444,2447,2450],{"class":162,"line":163},[160,2433,1835],{"class":166},[160,2435,1183],{"class":166},[160,2437,2438],{"class":259}," update",[160,2440,288],{"class":202},[160,2442,2443],{"class":305},"UpdateCustomerRequest",[160,2445,2446],{"class":202}," $request, ",[160,2448,2449],{"class":305},"Customer",[160,2451,2452],{"class":202}," $customer)\n",[160,2454,2455],{"class":162,"line":174},[160,2456,1320],{"class":202},[160,2458,2459,2462,2464,2467,2470,2472,2475],{"class":162,"line":182},[160,2460,2461],{"class":202},"        $customer",[160,2463,1336],{"class":166},[160,2465,2466],{"class":259},"update",[160,2468,2469],{"class":202},"($request",[160,2471,1336],{"class":166},[160,2473,2474],{"class":259},"validated",[160,2476,2477],{"class":202},"());\n",[160,2479,2480,2482,2485,2487,2489,2492,2494,2497],{"class":162,"line":190},[160,2481,355],{"class":166},[160,2483,2484],{"class":259}," back",[160,2486,1333],{"class":202},[160,2488,1336],{"class":166},[160,2490,2491],{"class":259},"withSuccess",[160,2493,288],{"class":202},[160,2495,2496],{"class":170},"'The customer was fully pimped.'",[160,2498,636],{"class":202},[160,2500,2501],{"class":162,"line":197},[160,2502,1164],{"class":202},[12,2504,2505,2506,2508],{},"I wish you a perfectly toasted 🍞 slice of bread that never falls on the wrong side! If it does, just put a ",[145,2507,897],{}," in front.",[2510,2511,2512],"style",{},"html pre.shiki code .s5nWI, html code.shiki .s5nWI{--shiki-light:#CF222E;--shiki-default:#CF222E;--shiki-dark:#FF7B72}html pre.shiki code .s-BGO, html code.shiki .s-BGO{--shiki-light:#0A3069;--shiki-default:#0A3069;--shiki-dark:#A5D6FF}html pre.shiki code .s_bOF, html code.shiki .s_bOF{--shiki-light:#1F2328;--shiki-default:#1F2328;--shiki-dark:#E6EDF3}html pre.shiki code .sd69k, html code.shiki .sd69k{--shiki-light:#8250DF;--shiki-default:#8250DF;--shiki-dark:#D2A8FF}html pre.shiki code .sQJ0q, html code.shiki .sQJ0q{--shiki-light:#953800;--shiki-default:#953800;--shiki-dark:#FFA657}html pre.shiki code .sDkKp, html code.shiki .sDkKp{--shiki-light:#0550AE;--shiki-default:#0550AE;--shiki-dark:#79C0FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s9BHP, html code.shiki .s9BHP{--shiki-light:#6E7781;--shiki-default:#6E7781;--shiki-dark:#8B949E}html pre.shiki code .sfEsd, html code.shiki .sfEsd{--shiki-light:#116329;--shiki-default:#116329;--shiki-dark:#7EE787}",{"title":156,"searchDepth":174,"depth":182,"links":2514},[2515,2516,2517],{"id":105,"depth":174,"text":106},{"id":727,"depth":174,"text":728},{"id":2238,"depth":174,"text":2239},[2519],{"link":2520,"desc":2521},"https:\u002F\u002Fgist.github.com\u002Fonlime\u002F4fc0e3e34dd54f0e70130419d93f125c","Gist","2023-04-04 00:35","Integrate vue3-toastify into VILT (Vue3, Inertia.js, Laravel, Tailwind) stack.",{"type":9,"value":2525},[2526,2533],[12,2527,14,2528],{},[16,2529,2530,25],{},[19,2531,24],{"href":21,"rel":2532},[23],[12,2534,28,2535,34,2538,40],{},[19,2536,33],{"href":31,"rel":2537},[23],[19,2539,39],{"href":37,"rel":2540},[23],"md","\u002Fimages\u002Fcovers\u002Fvue3-toastify-inertia.jpg",{},"\u002Farticles\u002F20230404-vue3-toastify-inertia",false,null,{"title":6,"description":2523},"articles\u002F20230404-vue3-toastify-inertia",[2550,2551,2552,2553,2554,155],"frontend","backend","vue.js","laravel","inertia.js","T2l84Ad8V-MABW3SL7h5ZZHUx5FQase_WsY2k8H0iQQ",[2557,2546],{"title":2558,"path":2559,"stem":2560,"createdAt":2561,"children":-1},"Vue.js 3 v-model two-way data binding for Dummies","\u002Farticles\u002F20220714-vue3-v-model-binding","articles\u002F20220714-vue3-v-model-binding","2022-07-14 12:00",1794817240031]