|
| 1 | +import ReactDOM from 'react-dom/client' |
| 2 | +import { Nav } from '../src/components' |
| 3 | +import { CodeExample } from '../src/components/CodeExample' |
| 4 | + |
| 5 | +function Recipe() { |
| 6 | + return ( |
| 7 | + <> |
| 8 | + <Nav recipeGallery /> |
| 9 | + <h1>SweetAlert2 + Laravel example</h1> |
| 10 | + <p> |
| 11 | + Here's the official Laravel integration:{' '} |
| 12 | + <a href="https://github.com/sweetalert2/sweetalert2-laravel"> |
| 13 | + https://github.com/sweetalert2/sweetalert2-laravel |
| 14 | + </a> |
| 15 | + </p> |
| 16 | + <p> |
| 17 | + It allow you to use SweetAlert2 in your Laravel application with ease. API options are the same as in the |
| 18 | + original plugin. |
| 19 | + </p> |
| 20 | + |
| 21 | + <pre style={{ maxWidth: '500px' }}> |
| 22 | + <code> |
| 23 | + <span className="unselectable">$ </span>composer require sweetalert2/laravel |
| 24 | + </code> |
| 25 | + </pre> |
| 26 | + |
| 27 | + <p> |
| 28 | + Include the SweetAlert2 template in your layout file (usually{' '} |
| 29 | + <strong>resources/views/layouts/app.blade.php</strong>): |
| 30 | + </p> |
| 31 | + |
| 32 | + <pre style={{ maxWidth: '500px' }}> |
| 33 | + <code>@include('sweetalert2::index')</code> |
| 34 | + </pre> |
| 35 | + |
| 36 | + <p> |
| 37 | + You can now run <strong>Swal::fire()</strong> anywhere in your Laravel application (controllers, middleware, |
| 38 | + etc.) to show a SweetAlert2 alert: |
| 39 | + </p> |
| 40 | + |
| 41 | + <CodeExample |
| 42 | + code={`use SweetAlert2\\Laravel\\Swal; |
| 43 | +
|
| 44 | +// same options as in Swal.fire() |
| 45 | +Swal::fire([ |
| 46 | + 'title' => 'Laravel + SweetAlert2 = <3', |
| 47 | + 'text' => 'This is a simple alert using SweetAlert2', |
| 48 | + 'icon' => 'success', |
| 49 | + 'confirmButtonText' => 'Cool' |
| 50 | +]); |
| 51 | +
|
| 52 | +// or with a custom icon |
| 53 | +Swal::success([ |
| 54 | + 'title' => 'Popup with a success icon', |
| 55 | +]); |
| 56 | +Swal::error([ |
| 57 | + 'title' => 'Popup with an error icon', |
| 58 | +]); |
| 59 | +Swal::warning([ |
| 60 | + 'title' => 'Popup with a warning icon', |
| 61 | +]); |
| 62 | +Swal::info([ |
| 63 | + 'title' => 'Popup with an info icon', |
| 64 | +]); |
| 65 | +Swal::question([ |
| 66 | + 'title' => 'Popup with a question icon', |
| 67 | +]); |
| 68 | +
|
| 69 | +// or a toast |
| 70 | +Swal::toast([ |
| 71 | + 'title' => 'Toast', |
| 72 | +]); |
| 73 | +
|
| 74 | +// or a toast with a custom icon |
| 75 | +Swal::toastSuccess([ |
| 76 | + 'title' => 'Toast with a success icon', |
| 77 | +]); |
| 78 | +Swal::toastError([ |
| 79 | + 'title' => 'Toast with an error icon', |
| 80 | +]); |
| 81 | +Swal::toastWarning([ |
| 82 | + 'title' => 'Toast with a warning icon', |
| 83 | +]); |
| 84 | +Swal::toastInfo([ |
| 85 | + 'title' => 'Toast with an info icon', |
| 86 | +]); |
| 87 | +Swal::toastQuestion([ |
| 88 | + 'title' => 'Toast with a question icon', |
| 89 | +]);`} |
| 90 | + language="php" |
| 91 | + style={{maxWidth: '600px'}} |
| 92 | + withoutCodepen |
| 93 | + /> |
| 94 | + |
| 95 | + <p> |
| 96 | + <img src="https://github.com/sweetalert2/sweetalert2-laravel/raw/main/sweetalert2-laravel.png" style={{ maxWidth: 840 }}/> |
| 97 | + </p> |
| 98 | + </> |
| 99 | + ) |
| 100 | +} |
| 101 | + |
| 102 | +ReactDOM.createRoot(document.getElementById('root')!).render(<Recipe />) |
0 commit comments