Personal Notes Parmi

temp terminal kode

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Secure Database Manager (URL Tersembunyi)') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6" style="margin: 0 auto;">

                       @if($errorMessage || session('error_message'))
                <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded">
                    {{ $errorMessage ?? session('error_message') }}
                </div>
            @endif

            @if(session('success_message'))
                <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded">
                    {{ session('success_message') }}
                </div>
            @endif

                       <div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
                <form method="POST" action="{{ route('db.secure') }}" class="space-y-4">
                    @csrf
                    <div class="grid grid-cols-1 md:grid-cols-5 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700">Host Server</label>
                            <input type="text" name="db_host" value="{{ request('db_host', '127.0.0.1') }}" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700">Port</label>
                            <input type="text" name="db_port" value="{{ request('db_port', '3306') }}" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700">Nama DB *</label>
                            <input type="text" name="db_name" value="{{ request('db_name') }}" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700">User DB *</label>
                            <input type="text" name="db_user" value="{{ request('db_user') }}" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700">Password DB</label>
                            <input type="password" name="db_pass" value="{{ request('db_pass') }}" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm text-sm">
                        </div>
                    </div>
                    <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-sm mt-3">
                        Hubungkan Basis Data
                    </button>
                </form>

                               @if(session('secure_db_credentials'))
                    <form method="POST" action="{{ route('db.secure.disconnect') }}" class="mt-2">
                        @csrf
                        <button type="submit" class="bg-red-600 hover:bg-red-700 text-white font-bold py-1.5 px-3 rounded text-xs">
                            🛑 Putuskan Koneksi (Clear Session)
                        </button>
                    </form>
                @endif
            </div>

            @if(count($tables) > 0)
                <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
                                       <div class="p-4 bg-white shadow sm:rounded-lg">
                        <h3 class="font-bold text-gray-900 mb-3 border-b pb-2 text-sm">Daftar Tabel ({{ count($tables) }})</h3>
                        <ul class="space-y-1 text-xs">
                            @foreach($tables as $table)
                                <li>
                                    <a href="{{ request()->fullUrlWithQuery(['table' => $table]) }}" class="block p-2 rounded {{ $selectedTable == $table ? 'bg-blue-500 text-white font-semibold' : 'text-gray-700 hover:bg-gray-100' }}">
                                        📁 {{ $table }}
                                    </a>
                                </li>
                            @endforeach
                        </ul>
                    </div>

                                       <div class="md:col-span-3 space-y-6">
                                               <div class="p-4 bg-white shadow sm:rounded-lg">
                            <h3 class="font-bold text-gray-900 mb-2 text-sm">Konsol SQL Murni (Kesaktian CLI)</h3>
                            <form method="POST" action="{{ route('db.secure.execute', request()->query()) }}" class="space-y-2">
                                @csrf
                                <textarea name="sql_query" rows="2" placeholder="Contoh: SELECT * FROM users WHERE id = 1" class="w-full rounded-md border-gray-300 font-mono text-xs">{{ old('sql_query') }}</textarea>
                                <button type="submit" class="bg-gray-800 hover:bg-gray-900 text-white text-xs font-semibold py-1.5 px-3 rounded">
                                    Jalankan Kueri
                                </button>
                            </form>

                                                       @if(session('query_result'))
                                <div class="mt-4 overflow-x-auto max-h-40 bg-gray-900 text-green-400 p-3 rounded font-mono text-xs">
                                    <pre>{{ print_r(session('query_result'), true) }}</pre>
                                </div>
                            @endif
                        </div>

                                               <div class="p-4 bg-white shadow sm:rounded-lg">
                            @if($selectedTable)
                                <h3 class="font-bold text-gray-900 mb-3 text-sm">Data Tabel: <span class="underline text-blue-600">{{ $selectedTable }}</span></h3>
                                <div class="overflow-x-auto max-h-96 border rounded">
                                    <table class="min-w-full divide-y divide-gray-200 text-xs">
                                        <thead class="bg-gray-50">
                                            <tr>
                                                @foreach($columns as $col)
                                                    <th class="px-3 py-2 text-left font-semibold text-gray-600 border-b uppercase">{{ $col }}</th>
                                                @endforeach
                                                <th class="px-3 py-2 text-left font-semibold text-red-600 border-b uppercase">Aksi</th>
                                            </tr>
                                        </thead>
                                        <tbody class="bg-white divide-y divide-gray-200">
                                            @forelse($rows as $row)
                                                <tr class="hover:bg-gray-50">
                                                    @foreach($columns as $col)
                                                        <td class="px-3 py-2 whitespace-nowrap text-gray-700 border-b">{{ $row->$col ?? 'NULL' }}</td>
                                                    @endforeach
                                                    <td class="px-3 py-2 whitespace-nowrap border-b">
                                                        @php 
                                                            $pKey = $columns[0] ?? 'id';
                                                            $pVal = $row->$pKey ?? null;
                                                        @endphp
                                                        @if($pVal)
                                                            <form method="POST" action="{{ route('db.secure.delete', $selectedTable) }}" onsubmit="return confirm('Hapus data?')">
                                                                @csrf
                                                                @method('DELETE')
                                                                <input type="hidden" name="id_column" value="{{ $pKey }}">
                                                                <input type="hidden" name="id_value" value="{{ $pVal }}">
                                                                <button type="submit" class="text-red-600 font-bold">🗑️ Hapus</button>
                                                            </form>
                                                        @else
                                                            <span class="text-gray-400">No ID</span>
                                                        @endif
                                                    </td>
                                                </tr>
                                            @empty
                                                <tr>
                                                    <td colspan="{{ count($columns) + 1 }}" class="px-3 py-4 text-center text-gray-400">Tabel Kosong.</td>
                                                </tr>
                                            @endforelse
                                        </tbody>
                                    </table>
                                </div>
                            @else
                                <div class="text-center py-12 text-gray-400 text-sm">
                                    Silakan klik salah satu nama tabel di menu kiri untuk membaca isinya.
                                </div>
                            @endif
                        </div>
                    </div>
                </div>
            @endif
        </div>
    </div>
</x-app-layout>