feat: setup database migrations and models for all roles

This commit is contained in:
sayasilvi 2025-11-25 20:23:55 +07:00
parent 5095aa52e6
commit b28b6b2e66
17 changed files with 436 additions and 117 deletions

21
app/Models/Admin.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Admin extends Authenticatable
{
use Notifiable;
protected $table = 'admins'; protected $primaryKey = 'id';
protected $fillable = [
'nama', 'username', 'password',
];
protected $hidden = [
'password',
];
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DetailTransaksi extends Model
{
use HasFactory;
protected $table = 'detail_transaksis';
protected $fillable = [
'transaksi_id',
'produk_id',
'jumlah',
'harga_satuan',
'subtotal'
];
public function transaksi()
{
return $this->belongsTo(Transaksi::class, 'transaksi_id');
}
public function produk()
{
return $this->belongsTo(Produk::class, 'produk_id');
}
}

30
app/Models/Pembeli.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Pembeli extends Authenticatable
{
use Notifiable;
protected $table = 'pembelis';
protected $fillable = [
'nama_lengkap',
'username',
'password',
'no_hp',
'alamat'
];
protected $hidden = [
'password',
];
public function transaksis()
{
return $this->hasMany(Transaksi::class, 'pembeli_id');
}
}

23
app/Models/Pesan.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Pesan extends Model
{
use HasFactory;
protected $table = 'pesans';
protected $fillable = [
'pengirim_id',
'pengirim_type',
'penerima_id',
'penerima_type',
'isi_pesan',
'sudah_dibaca'
];
}

32
app/Models/Petani.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable; // PENTING: Ganti ini
use Illuminate\Notifications\Notifiable;
class Petani extends Authenticatable
{
use Notifiable;
protected $table = 'petanis';
protected $fillable = [
'nama_lengkap',
'username',
'password',
'no_hp',
'alamat',
'nama_usaha',
'status_akun'
];
protected $hidden = [
'password',
];
public function produks()
{
return $this->hasMany(Produk::class, 'petani_id');
}
}

32
app/Models/Produk.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Produk extends Model
{
use HasFactory;
protected $table = 'produks';
protected $fillable = [
'petani_id',
'nama_produk',
'harga',
'stok',
'deskripsi',
'foto_produk'
];
public function petani()
{
return $this->belongsTo(Petani::class, 'petani_id');
}
public function detailTransaksis()
{
return $this->hasMany(DetailTransaksi::class, 'produk_id');
}
}

32
app/Models/Transaksi.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Transaksi extends Model
{
use HasFactory;
protected $table = 'transaksis';
protected $fillable = [
'pembeli_id',
'tanggal_transaksi',
'alamat_pengiriman',
'total_harga',
'status',
'kode_invoice'
];
public function pembeli()
{
return $this->belongsTo(Pembeli::class, 'pembeli_id');
}
public function details()
{
return $this->hasMany(DetailTransaksi::class, 'transaksi_id');
}
}

View File

@ -1,41 +0,0 @@
<?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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('username')->unique();
$table->string('email')->unique()->nullable();
$table->string('password');
// Role: admin, petani, pembeli
$table->enum('role', ['admin', 'petani', 'pembeli']);
$table->string('no_hp')->nullable();
$table->text('alamat')->nullable();
// Khusus Petani
$table->enum('status_akun', ['pending', 'aktif', 'ditolak'])->default('aktif');
$table->string('nama_bank')->nullable();
$table->string('no_rekening')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
};

View File

@ -1,30 +0,0 @@
<?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('produk', function (Blueprint $table) {
$table->id();
$table->foreignId('petani_id')->constrained('users')->onDelete('cascade');
$table->string('nama_produk');
$table->text('deskripsi')->nullable();
$table->decimal('harga', 12, 2);
$table->integer('stok');
$table->string('foto')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('produk');
}
};

View File

@ -1,46 +0,0 @@
<?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('transaksi', function (Blueprint $table) {
$table->id();
$table->string('kode_transaksi')->unique();
$table->foreignId('pembeli_id')->constrained('users')->onDelete('cascade');
$table->foreignId('petani_id')->constrained('users')->onDelete('cascade');
$table->date('tanggal_transaksi');
$table->decimal('total_harga', 12, 2);
$table->enum('status', [
'menunggu_pembayaran',
'menunggu_verifikasi',
'diproses',
'dikirim',
'selesai',
'ditolak'
])->default('menunggu_pembayaran');
$table->string('bukti_transfer')->nullable();
$table->decimal('biaya_ongkir', 12, 2)->default(0);
$table->string('resi_pengiriman')->nullable();
$table->text('alamat_pengiriman');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('transaksi');
}
};

View File

@ -0,0 +1,30 @@
<?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('admins', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->string('username')->unique();
$table->string('password');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('admins');
}
};

View File

@ -0,0 +1,37 @@
<?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('petanis', function (Blueprint $table) {
$table->id();
$table->string('nama_lengkap');
$table->string('username')->unique();
$table->string('password');
$table->string('no_hp', 15);
$table->text('alamat');
$table->string('nama_usaha')->nullable();
// Status Verifikasi
$table->enum('status_akun', ['menunggu', 'aktif', 'ditolak'])->default('menunggu');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('petanis');
}
};

View 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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('pembelis', function (Blueprint $table) {
$table->id();
$table->string('nama_lengkap');
$table->string('username')->unique();
$table->string('password');
$table->string('no_hp', 15);
$table->text('alamat');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pembelis');
}
};

View File

@ -0,0 +1,35 @@
<?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('produks', function (Blueprint $table) {
$table->id();
$table->foreignId('petani_id')->constrained('petanis')->onDelete('cascade');
$table->string('nama_produk');
$table->decimal('harga', 12, 0);
$table->integer('stok');
$table->text('deskripsi');
$table->string('foto_produk')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('produks');
}
};

View File

@ -0,0 +1,35 @@
<?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('transaksis', function (Blueprint $table) {
$table->id();
$table->foreignId('pembeli_id')->constrained('pembelis')->onDelete('cascade');
$table->dateTime('tanggal_transaksi');
$table->text('alamat_pengiriman');
$table->decimal('total_harga', 15, 0);
$table->enum('status', ['menunggu_konfirmasi', 'diproses', 'dikirim', 'selesai', 'batal'])
->default('menunggu_konfirmasi');
$table->string('kode_invoice')->unique()->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('transaksis');
}
};

View 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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('detail_transaksis', function (Blueprint $table) {
$table->id();
$table->foreignId('transaksi_id')->constrained('transaksis')->onDelete('cascade');
$table->foreignId('produk_id')->constrained('produks')->onDelete('cascade');
$table->integer('jumlah');
$table->decimal('harga_satuan', 12, 0);
$table->decimal('subtotal', 15, 0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('detail_transaksis');
}
};

View File

@ -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('pesans', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('pengirim_id');
$table->string('pengirim_type');
$table->unsignedBigInteger('penerima_id');
$table->string('penerima_type');
$table->text('isi_pesan');
$table->boolean('sudah_dibaca')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pesans');
}
};