47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\PermohonanTransfer;
|
|
use App\Models\RumahIbadah;
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void {}
|
|
|
|
public function boot(): void
|
|
{
|
|
View::composer('*', function ($view) {
|
|
try {
|
|
$view->with('appSettings', Setting::getAll());
|
|
} catch (\Throwable) {
|
|
$view->with('appSettings', []);
|
|
}
|
|
|
|
try {
|
|
$pendingTransferCount = 0;
|
|
|
|
if (auth()->check()) {
|
|
$user = auth()->user();
|
|
|
|
if ($user->hasRole('administrator')) {
|
|
$pendingTransferCount = PermohonanTransfer::where('status', 'pending')->count();
|
|
} elseif ($user->hasRole('pengurus_ibadah')) {
|
|
$ownedIbadahIds = RumahIbadah::where('user_id', $user->id)->pluck('id');
|
|
$pendingTransferCount = PermohonanTransfer::where('status', 'pending')
|
|
->whereIn('ke_ibadah_id', $ownedIbadahIds)
|
|
->count();
|
|
}
|
|
}
|
|
|
|
$view->with('pendingTransferCount', $pendingTransferCount);
|
|
} catch (\Throwable) {
|
|
$view->with('pendingTransferCount', 0);
|
|
}
|
|
});
|
|
}
|
|
}
|