Archived
1
0
Fork 0
This repository has been archived on 2026-06-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
wow-raid-bingo/app/Http/Livewire/AlertContainer.php

58 lines
1.1 KiB
PHP

<?php
namespace App\Http\Livewire;
use Illuminate\Support\Facades\Session;
use Livewire\Component;
class AlertContainer extends Component
{
/**
* List of alert types.
*/
protected array $_types = [
'info',
'success',
'warning',
'danger'
];
/**
* Event listeners
*/
protected $listeners = [
// Add message when "alert" event is fired.
'alert' => 'addMessage'
];
/**
* Alert messages.
*/
public array $messages = [];
public function mount()
{
// Load messages from session
foreach ($this->_types as $type) {
if (Session::has($type)) {
$this->addMessage($type, Session::get($type));
}
}
}
/**
* Add a message to the container.
*/
public function addMessage(string $type, string $message)
{
$this->messages[] = [$type, $message];
}
/**
* Render the messages
*/
public function render()
{
return view('livewire.alert-container');
}
}