Deploy Ladill Give / deploy (push) Successful in 34s
Wire UserProfileMenu and shared Blade partial into topbar, mobile nav, and layouts so menu items match the account portal (Ladill Mail excluded). Co-authored-by: Cursor <cursoragent@cursor.com>
97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class UserProfileMenu
|
|
{
|
|
/** @return list<array<string, mixed>> */
|
|
public static function items(?Authenticatable $user = null): array
|
|
{
|
|
$user ??= auth()->user();
|
|
|
|
if (! $user) {
|
|
return [];
|
|
}
|
|
|
|
$items = [];
|
|
|
|
foreach ([
|
|
['label' => 'Home', 'path' => '', 'host' => 'home'],
|
|
['label' => 'Profile', 'path' => 'profile'],
|
|
['label' => 'Account Settings', 'path' => 'account-settings'],
|
|
['label' => 'Dashboard', 'path' => 'dashboard'],
|
|
['label' => 'Billing', 'path' => 'billing'],
|
|
] as $link) {
|
|
$items[] = [
|
|
'type' => 'link',
|
|
'label' => $link['label'],
|
|
'href' => self::platformUrl($link['host'] ?? 'account', $link['path']),
|
|
];
|
|
}
|
|
|
|
if (self::userIsAdmin($user)) {
|
|
$items[] = [
|
|
'type' => 'link',
|
|
'label' => 'Admin',
|
|
'href' => self::platformUrl('account', 'admin'),
|
|
];
|
|
}
|
|
|
|
if (Route::has('logout')) {
|
|
$items[] = [
|
|
'type' => 'logout',
|
|
'label' => 'Logout',
|
|
'action' => route('logout'),
|
|
];
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
private static function platformUrl(string $host, string $path = ''): string
|
|
{
|
|
if ($host === 'home') {
|
|
if (function_exists('ladill_home_url')) {
|
|
return ladill_home_url($path);
|
|
}
|
|
|
|
$domain = config('app.home_domain');
|
|
if (! $domain) {
|
|
$platform = (string) config('app.platform_domain', parse_url((string) config('app.url', ''), PHP_URL_HOST) ?: '');
|
|
$domain = $platform !== '' ? 'home.'.$platform : (string) config('app.account_domain');
|
|
}
|
|
|
|
return self::absoluteUrl((string) $domain, $path);
|
|
}
|
|
|
|
if (function_exists('ladill_account_url')) {
|
|
return ladill_account_url($path);
|
|
}
|
|
|
|
return self::absoluteUrl((string) config('app.account_domain'), $path);
|
|
}
|
|
|
|
private static function absoluteUrl(string $domain, string $path = ''): string
|
|
{
|
|
$base = 'https://'.trim($domain, '/');
|
|
|
|
if ($path === '') {
|
|
return $base;
|
|
}
|
|
|
|
return $base.'/'.ltrim($path, '/');
|
|
}
|
|
|
|
private static function userIsAdmin(Authenticatable $user): bool
|
|
{
|
|
if (method_exists($user, 'isAdmin')) {
|
|
return $user->isAdmin();
|
|
}
|
|
|
|
return (bool) ($user->is_admin ?? false);
|
|
}
|
|
}
|