57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Resources\UserResource;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
final class InertiaProvider
|
|
{
|
|
private string $vueFile;
|
|
private array $props;
|
|
|
|
private ?User $user;
|
|
|
|
public function __construct(string $vueFile, array $props) {
|
|
$this->user = auth()->user();
|
|
$this->vueFile = $vueFile;
|
|
$this->props = $props;
|
|
}
|
|
|
|
public function render() : Response {
|
|
$this->props['navbar'] = $this->generateNavbar();
|
|
$this->props['tenant'] = app('tenant');
|
|
$this->props['user'] = new UserResource($this->user)->toArray(request());
|
|
$this->props['currentPath'] = request()->path();
|
|
$this->props['availableLocalGroups'] = Tenant::where(['is_active_local_group' => true])->get();
|
|
|
|
return Inertia::render(
|
|
str_replace('/', '/Views/', $this->vueFile),
|
|
$this->props
|
|
);
|
|
}
|
|
|
|
private function generateNavbar() : array {
|
|
$navigation = [
|
|
'personal' => [],
|
|
'common' => [],
|
|
'costunits' => [],
|
|
'events' => [],
|
|
];
|
|
|
|
$navigation['personal'][] = ['url' => '/', 'display' => 'Home'];
|
|
if (null !== $this->user) {
|
|
$navigation['personal'][] = ['url' => '/personal-data', 'display' => 'Meine Daten'];
|
|
$navigation['personal'][] = ['url' => '/messages', 'display' => 'Meine Nachrichten'];
|
|
}
|
|
|
|
$navigation['common'][] = ['url' => '/capture-invoice', 'display' => 'Neue Abrechnung'];
|
|
$navigation['common'][] = ['url' => '/available-events', 'display' => 'Verfügbare Veranstaltungen'];
|
|
|
|
return $navigation;
|
|
}
|
|
}
|