- View Composer 변수는 Blade 컴포넌트에서 접근 불가 - View::share로 전역 공유하여 컴포넌트에서도 접근 가능하도록 수정 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Services\Sales\SalesManagerService;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ViewServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// 모든 뷰에 테넌트 목록 공유 (전역용)
|
|
View::composer('*', function ($view) {
|
|
if (auth()->check()) {
|
|
$globalTenants = Tenant::active()
|
|
->orderBy('company_name')
|
|
->get(['id', 'company_name', 'code']);
|
|
|
|
$view->with('globalTenants', $globalTenants);
|
|
}
|
|
});
|
|
|
|
// 사이드바 메뉴 뱃지 데이터 (전역 공유 - 컴포넌트에서도 접근 가능)
|
|
View::composer('partials.sidebar', function ($view) {
|
|
$menuBadges = [
|
|
'byRoute' => [], // 라우트명 기준
|
|
'byUrl' => [], // URL 기준
|
|
];
|
|
|
|
if (auth()->check()) {
|
|
try {
|
|
$salesManagerService = app(SalesManagerService::class);
|
|
$approvalStats = $salesManagerService->getApprovalStats();
|
|
|
|
// 영업파트너 승인 대기 건수
|
|
if ($approvalStats['pending'] > 0) {
|
|
$menuBadges['byRoute']['sales.managers.approvals'] = $approvalStats['pending'];
|
|
$menuBadges['byUrl']['/sales/managers/approvals'] = $approvalStats['pending'];
|
|
}
|
|
} catch (\Exception $e) {
|
|
// 서비스 오류 시 무시
|
|
}
|
|
}
|
|
|
|
// View::share로 전역 공유 (Blade 컴포넌트에서도 접근 가능)
|
|
View::share('menuBadges', $menuBadges);
|
|
});
|
|
}
|
|
}
|