Left Icon Right Icon
Squehub SqueHub

📢 Notifications in Squehub

The Notification class in app/core/Notification.php handles one-time flash messages such as success, error, info, and warning. Messages are stored in session and automatically cleared after being retrieved.

📦 Namespace

To use this feature, include the namespace at the top of your file:

use App\Core\Notification;

📂 Methods

  • Notification::flash('type', 'message') – Store a message of a given type in session.
  • Notification::get('type') – Retrieve a single message and auto-remove it.
  • Notification::all() – Retrieve all available types at once.

🎨 Usage in Blade-like View

Use @hasNotification() in your views to display flash messages conditionally:

@hasNotification('success')
    <p style="color: green;">{{ $message }}. Redirecting in 3s...</p>
@endhasNotification

@hasNotification('info')
    <p style="color: orange;">{{ $message }}</p>
@endhasNotification

@hasNotification('error')
    <p style="color: red;">{{ $message }}</p>
@endhasNotification

🧱 Global Layout Integration

You can show flash messages site-wide by adding this snippet to your layout (e.g. layouts/main.squehub.php):

@hasNotification('success')
    <div class="alert alert-success">{{ $message }}</div>
@endhasNotification

@hasNotification('error')
    <div class="alert alert-danger">{{ $message }}</div>
@endhasNotification

@hasNotification('info')
    <div class="alert alert-info">{{ $message }}</div>
@endhasNotification

📘 Example in Controller

use App\Core\Notification;

Notification::flash('success', 'User created successfully!');
redirect()->to('/dashboard');

📤 Displaying All Notifications

You can retrieve and display all messages manually if needed:

foreach (Notification::all() as $type => $message) {
    echo "<div class='alert alert-$type'>$message</div>";
}

✅ Summary

  • Use Notification::flash() to store feedback after an action.
  • Use @hasNotification() in views to check and display messages.
  • All messages auto-expire after display.
💡 Tip: Keep your messages user-friendly and concise. Combine notifications with redirects to provide smooth user feedback flows.
;