Fix peminjaman FK and use id_buku in views
Add migration to fix peminjaman.id_buku foreign key: modify column to INT UNSIGNED and re-create FK referencing buku.id_buku with cascadeOnDelete. Update admin peminjaman blades to use $b->id_buku for option values. Remove unused imports and tidy up formatting/whitespace in Peminjaman and AdminPeminjaman controllers (including small reformat of Fonnte API payload). These changes ensure the dropdowns use the correct book identifier and the DB relation is consistent.
This commit is contained in:
parent
c2a61ea5a0
commit
ca98d0a665
|
|
@ -6,10 +6,8 @@
|
|||
use App\Models\Buku;
|
||||
use App\Models\Anggota;
|
||||
use Illuminate\Http\Request;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AdminPeminjamanController extends Controller
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PeminjamanController extends Controller
|
||||
{
|
||||
|
|
@ -128,7 +127,6 @@ public function store(Request $request)
|
|||
if (file_exists($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Bila error (misal: memori PDF kurang, library dompdf crash, timeout dari Fonnte)
|
||||
// Error ditangkap agar sistem tidak langsung menampilkan layar error 500 ke User.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
try {
|
||||
DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY peminjaman_ibfk_2');
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY fk_peminjaman_buku');
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
Schema::table('peminjaman', function (Blueprint $table) {
|
||||
$table->dropForeign(['id_buku']);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
DB::statement('ALTER TABLE peminjaman MODIFY id_buku INT UNSIGNED NOT NULL');
|
||||
|
||||
Schema::table('peminjaman', function (Blueprint $table) {
|
||||
$table->foreign('id_buku')
|
||||
->references('id_buku')
|
||||
->on('buku')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
try {
|
||||
Schema::table('peminjaman', function (Blueprint $table) {
|
||||
$table->dropForeign(['id_buku']);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
DB::statement('ALTER TABLE peminjaman MODIFY id_buku BIGINT UNSIGNED NOT NULL');
|
||||
|
||||
Schema::table('peminjaman', function (Blueprint $table) {
|
||||
$table->foreign('id_buku')
|
||||
->references('id')
|
||||
->on('bukus')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -41,7 +41,7 @@ class="w-full border-gray-300 rounded-lg shadow-sm focus:border-blue-500 focus:r
|
|||
class="w-full border-gray-300 rounded-lg shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
<option value="">-- Pilih Buku --</option>
|
||||
@foreach ($buku as $b)
|
||||
<option value="{{ $b->id }}" {{ old('id_buku') == $b->id ? 'selected' : '' }}>
|
||||
<option value="{{ $b->id_buku }}" {{ old('id_buku') == $b->id_buku ? 'selected' : '' }}>
|
||||
{{ $b->bibid }} - {{ $b->judul }} (Stok: {{ $b->eksemplar }})
|
||||
</option>
|
||||
@endforeach
|
||||
|
|
|
|||
|
|
@ -251,7 +251,8 @@ class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indi
|
|||
required>
|
||||
<option value="">-- Pilih Buku --</option>
|
||||
@foreach ($buku as $b)
|
||||
<option value="{{ $b->id }}" {{ old('id_buku') == $b->id ? 'selected' : '' }}>
|
||||
<option value="{{ $b->id_buku }}"
|
||||
{{ old('id_buku') == $b->id_buku ? 'selected' : '' }}>
|
||||
{{ $b->bibid }} - {{ $b->judul }} (Stok: {{ $b->eksemplar }})
|
||||
</option>
|
||||
@endforeach
|
||||
|
|
@ -440,7 +441,7 @@ class="mt-1 block w-full border-gray-300 focus:border-indigo-500 focus:ring-indi
|
|||
required>
|
||||
<option value="">-- Pilih Buku --</option>
|
||||
@foreach ($buku as $b)
|
||||
<option value="{{ $b->id }}">{{ $b->bibid }} - {{ $b->judul }}
|
||||
<option value="{{ $b->id_buku }}">{{ $b->bibid }} - {{ $b->judul }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue