add('chat', 'chat::Unread', fn (User $user) => ['unread' => 3], sort: 10); * * Liefert der Callback null, erscheint das Symbol für diese Person nicht. */ class HeaderItems { /** @var array */ private array $items = []; public function add(string $key, string $component, callable $props, int $sort = 50): void { $this->items[$key] = compact('component', 'props', 'sort'); } /** * @return list}> */ public function resolve(User $user): array { $access = app(PluginAccess::class); return collect($this->items) ->filter(fn ($item, $key) => $access->allows($key, $user)) ->sortBy('sort') ->map(function (array $item, string $key) use ($user) { try { $props = ($item['props'])($user); } catch (Throwable $e) { report($e); return null; } return $props === null ? null : ['key' => $key, 'component' => $item['component'], 'props' => $props]; }) ->filter()->values()->all(); } }