Use SweetAlert inside Laravel Controller
Laravel is a popular PHP framework that provides a simple and elegant way to create web applications. One of the features that Laravel offers is the ability to use sweetalert, a JavaScript library that displays beautiful and responsive alert messages. Sweetalert can be easily integrated using sweet alert package from realrashid. This package allows you to use the sweetalert methods in your Laravel controllers, views, and routes.
In this tutorial we will use the sweet alert package from realrashid and not using the Javascript / Ajax metho
Install Sweet Alert Package
composer require realrashid/sweet-alert
Publish package assets
php artisan sweetalert:publish
Include the script in the master layout- resources/views/layouts/app.blade.php
Place the script above between the <body> … </body> tags
@include(‘sweetalert::alert’)
Edit Register Controller to Display sweet alert message once user has successfully registered.
use RealRashidSweetAlertFacadesAlert;
protected function create(array $data)
{
$user = User::create([
‘name’ => $data[‘name’],
’email’ => $data[’email’],
‘password’ => Hash::make($data[‘password’]),
]);
Alert::success(‘Congrats’, ‘You’ve Successfully Registered’);
return $user;
}