- View::with() → View::share()로 변경하여 <x-sidebar.menu-item> 컴포넌트에서 $menuBadges 접근 가능하도록 수정
94 lines
3.3 KiB
PHP
94 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Boards\File;
|
|
use App\Models\Boards\Post;
|
|
use App\Models\Tenants\Department;
|
|
use App\Models\User;
|
|
use App\Observers\FileObserver;
|
|
use App\Services\ApprovalService;
|
|
use App\Services\SidebarMenuService;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
// SidebarMenuService 싱글턴 등록
|
|
$this->app->singleton(SidebarMenuService::class);
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// File Observer: 파일 생성/삭제 시 테넌트 저장소 사용량 자동 업데이트
|
|
File::observe(FileObserver::class);
|
|
|
|
// Morph Map: Polymorphic 관계 모델 등록
|
|
Relation::enforceMorphMap([
|
|
'user' => User::class,
|
|
'post' => Post::class,
|
|
'department' => Department::class,
|
|
]);
|
|
|
|
// 일회성 메뉴명 변경: 협력사관리 → 거래처 관리
|
|
if (! Cache::has('menu_rename_partner_to_vendor')) {
|
|
$updated = DB::table('menus')
|
|
->where('tenant_id', 1)
|
|
->whereIn('name', ['협력사관리', '협력사 관리'])
|
|
->update(['name' => '거래처 관리']);
|
|
if ($updated > 0) {
|
|
Cache::put('menu_rename_partner_to_vendor', true, now()->addYear());
|
|
}
|
|
}
|
|
|
|
// 사이드바에 메뉴 데이터 전달
|
|
View::composer('partials.sidebar', function ($view) {
|
|
$menuService = app(SidebarMenuService::class);
|
|
$menusBySection = $menuService->getMenusBySection();
|
|
|
|
// 결재 뱃지 건수
|
|
$menuBadges = ['byRoute' => [], 'byUrl' => []];
|
|
if (auth()->check()) {
|
|
try {
|
|
$counts = app(ApprovalService::class)->getBadgeCounts(auth()->id());
|
|
$menuBadges = [
|
|
'byRoute' => [
|
|
'approvals.pending' => $counts['pending'],
|
|
'approvals.drafts' => $counts['draft'],
|
|
'approvals.references' => $counts['reference_unread'],
|
|
],
|
|
'byUrl' => [
|
|
'/approval-mgmt/pending' => $counts['pending'],
|
|
'/approval-mgmt/drafts' => $counts['draft'],
|
|
'/approval-mgmt/references' => $counts['reference_unread'],
|
|
],
|
|
];
|
|
} catch (\Throwable $e) {
|
|
// 테이블 미존재 등 예외 무시
|
|
}
|
|
}
|
|
|
|
// menuBadges는 Blade 컴포넌트(<x-sidebar.menu-item>)에서도 접근 필요
|
|
// $view->with()는 컴포넌트 격리 스코프에 전달 안 되므로 View::share 사용
|
|
View::share('menuBadges', $menuBadges);
|
|
|
|
$view->with([
|
|
'mainMenus' => $menusBySection['main'],
|
|
'toolsMenus' => $menusBySection['tools'],
|
|
'labsMenus' => $menusBySection['labs'],
|
|
]);
|
|
});
|
|
}
|
|
}
|