coderatio/laranotify
Advanced Laravel notifications/alerts built on Bootstrap Notify/Growl. Chain fluent methods to show elegant on-screen messages, blockables, and notifications, with template customization and publishable sample views.
Installation
composer require coderatio/laranotify
Publish the config file:
php artisan vendor:publish --provider="Coderatio\Laranotify\LaranotifyServiceProvider"
Basic Usage
Include the package’s JS/CSS in your layout (e.g., resources/views/layouts/app.blade.php):
@include('laranotify::notify')
Trigger a notification in a controller:
use Coderatio\Laranotify\Facades\Laranotify;
Laranotify::success('Task completed!')->send();
First Use Case Display a success message after form submission:
// In your controller
public function store(Request $request) {
$validated = $request->validate([...]);
// Save logic...
Laranotify::success('Record saved successfully')->send();
return redirect()->back();
}
Dynamic Notifications Pass variables to notifications for dynamic content:
Laranotify::info("User {$user->name} logged in")->send();
Alerts with Actions
Use withButton() to add clickable buttons:
Laranotify::warning("Session expired")
->withButton('Refresh', 'javascript:location.reload()')
->send();
Blocking Notifications Prevent user interaction until dismissed:
Laranotify::blockable('Update required', 'Please update your profile')
->send();
Queueing Notifications Store notifications in the session for delayed display (e.g., after redirect):
Laranotify::queue('success', 'Processing...')->send();
Blade Integration Check for queued notifications in your layout:
@if(session()->has('laranotify'))
@include('laranotify::notify')
@endif
API Responses Return notifications in JSON responses:
return response()->json([
'success' => true,
'message' => Laranotify::success('Data fetched')->toArray()
]);
Custom Templates Override default views by publishing assets:
php artisan vendor:publish --tag=laranotify-views
Session Dependency
SESSION_DRIVER is configured (e.g., file, database, or redis).'session' => ['driver' => 'file'] to .env if needed.JavaScript Conflicts
laranotify.js.<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
@include('laranotify::notify')
Queued Notifications Not Showing
laranotify is added to the session middleware group in app/Http/Kernel.php:
'web' => [
\Illuminate\Session\Middleware\AuthenticateSession::class,
// ... other middleware
\Coderatio\Laranotify\Middleware\LaranotifyMiddleware::class,
],
Check Session Data Dump queued notifications in a route:
Route::get('/debug-notify', function() {
dd(session('laranotify'));
});
Inspect Console Errors Look for missing jQuery/Bootstrap dependencies or conflicts with other plugins.
Custom Icons Override icons in the config:
'icons' => [
'success' => 'fas fa-check-circle',
'error' => 'fas fa-times-circle',
],
Add Notification Types
Extend the Laranotify facade to support custom types:
// In a service provider
Laranotify::extend('custom', function($message) {
return Laranotify::make('custom', $message, 'bg-primary');
});
Localization Translate messages using Laravel’s translation system:
Laranotify::success(__('messages.task_completed'))->send();
How can I help you explore Laravel packages today?