Files
CKB/app/Providers/AppServiceProvider.php

57 lines
1.5 KiB
PHP
Executable File

<?php
namespace App\Providers;
use App\Models\Menu;
use Carbon\Carbon;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\URL;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Carbon::setLocale('id');
View::composer(['layouts.partials.sidebarMenu', 'dashboard', 'dealer_recap', 'back.*', 'warehouse_management.*'], function ($view) {
$menuQuery = Menu::all();
$menus = [];
foreach($menuQuery as $menu) {
$menus[$menu->link] = $menu;
}
$view->with('menus', $menus);
});
// Force HTTPS in production if needed
if (config('app.env') === 'production') {
// Force the application URL to include port if specified
$appUrl = config('app.url');
if ($appUrl) {
URL::forceRootUrl($appUrl);
// Parse URL to check if it's HTTPS
$parsedUrl = parse_url($appUrl);
if (isset($parsedUrl['scheme']) && $parsedUrl['scheme'] === 'https') {
URL::forceScheme('https');
}
}
}
}
}