<?php

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

$basePathCandidates = [
    realpath(__DIR__ . '/..'),
    realpath(__DIR__ . '/laravel'),
];

$basePath = null;

foreach ($basePathCandidates as $candidate) {
    if ($candidate
        && file_exists($candidate . '/vendor/autoload.php')
        && file_exists($candidate . '/bootstrap/app.php')) {
        $basePath = $candidate;
        break;
    }
}

if (!$basePath) {
    throw new RuntimeException('Laravel base path tidak ditemukan.');
}

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = $basePath . '/storage/framework/maintenance.php')) {
    require $maintenance;
}

// Register the Composer autoloader...
require $basePath . '/vendor/autoload.php';

// Bootstrap Laravel and handle the request...
/** @var Application $app */
$app = require_once $basePath . '/bootstrap/app.php';

$app->usePublicPath(__DIR__);

$app->handleRequest(Request::capture());