Add models and migrations for Anggota, Buku, Kategori, and Peminjaman
This commit is contained in:
30
app/Models/Anggota.php
Normal file
30
app/Models/Anggota.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class Anggota extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'nama',
|
||||||
|
'email',
|
||||||
|
'no_telepon',
|
||||||
|
'alamat',
|
||||||
|
'tanggal_bergabung',
|
||||||
|
'status',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'tanggal_bergabung' => 'date',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function peminjamans()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Peminjaman::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Models/Buku.php
Normal file
35
app/Models/Buku.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class Buku extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'kategori_id',
|
||||||
|
'judul',
|
||||||
|
'pengarang',
|
||||||
|
'penerbit',
|
||||||
|
'tahun_terbit',
|
||||||
|
'isbn',
|
||||||
|
'stok',
|
||||||
|
'stok_tersedia',
|
||||||
|
'sinopsis',
|
||||||
|
'cover',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function kategori()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Kategori::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function peminjamans()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Peminjaman::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
app/Models/Kategori.php
Normal file
21
app/Models/Kategori.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Kategori extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'nama_kategori',
|
||||||
|
'deskripsi',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function bukus()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Buku::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Models/Peminjaman.php
Normal file
38
app/Models/Peminjaman.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Peminjaman extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'anggota_id',
|
||||||
|
'buku_id',
|
||||||
|
'tanggal_pinjam',
|
||||||
|
'tanggal_kembali_rencana',
|
||||||
|
'tanggal_kembali_aktual',
|
||||||
|
'status',
|
||||||
|
'denda',
|
||||||
|
'catatan',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'tanggal_pinjam' => 'date',
|
||||||
|
'tanggal_kembali_rencana' => 'date',
|
||||||
|
'tanggal_kembali_aktual' => 'date',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function anggota()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Anggota::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buku()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Buku::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('anggotas', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('nama');
|
||||||
|
$table->string('email')->unique();
|
||||||
|
$table->string('no_telepon', 15)->nullable();
|
||||||
|
$table->text('alamat')->nullable();
|
||||||
|
$table->date('tanggal_bergabung');
|
||||||
|
$table->enum('status', ['aktif', 'nonaktif'])->default('aktif');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('anggotas');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('kategoris', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('nama_kategori');
|
||||||
|
$table->text('deskripsi')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('kategoris');
|
||||||
|
}
|
||||||
|
};
|
||||||
32
database/migrations/2026_03_17_121408_create_bukus_table.php
Normal file
32
database/migrations/2026_03_17_121408_create_bukus_table.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('bukus', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('kategori_id')->constrained('kategoris')->onDelete('cascade');
|
||||||
|
$table->string('judul');
|
||||||
|
$table->string('pengarang');
|
||||||
|
$table->string('penerbit');
|
||||||
|
$table->year('tahun_terbit');
|
||||||
|
$table->string('isbn', 20)->unique();
|
||||||
|
$table->integer('stok')->default(0);
|
||||||
|
$table->integer('stok_tersedia')->default(0);
|
||||||
|
$table->text('sinopsis')->nullable();
|
||||||
|
$table->string('cover')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('bukus');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('peminjamans', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('anggota_id')->constrained('anggotas')->onDelete('cascade');
|
||||||
|
$table->foreignId('buku_id')->constrained('bukus')->onDelete('cascade');
|
||||||
|
$table->date('tanggal_pinjam');
|
||||||
|
$table->date('tanggal_kembali_rencana');
|
||||||
|
$table->date('tanggal_kembali_aktual')->nullable();
|
||||||
|
$table->enum('status', ['dipinjam', 'dikembalikan', 'terlambat'])->default('dipinjam');
|
||||||
|
$table->integer('denda')->default(0);
|
||||||
|
$table->text('catatan')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('peminjamans');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user