2020-03-01 18:21:16 +01:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-03-01 18:21:16 +01:00
|
|
|
namespace Engelsystem\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
trait HasUserNotifications
|
|
|
|
{
|
2022-12-14 19:15:20 +01:00
|
|
|
protected function addNotification(string|array $value, string $type = 'messages'): void
|
2020-03-01 18:21:16 +01:00
|
|
|
{
|
|
|
|
session()->set(
|
|
|
|
$type,
|
|
|
|
array_merge(session()->get($type, []), [$value])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getNotifications(): array
|
|
|
|
{
|
|
|
|
$return = [];
|
|
|
|
foreach (['errors', 'warnings', 'information', 'messages'] as $type) {
|
|
|
|
$return[$type] = Collection::make(Arr::flatten(session()->get($type, [])));
|
|
|
|
session()->remove($type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|