From 02890ae9ae9def8571646bbae60af3a00bf084b7 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Mon, 29 Jun 2026 09:46:44 +0700 Subject: [PATCH] model petani --- app/Models/Pertanian/Petani.php | 77 +++++++++++++++++++ ...6_26_180741_create_petani_master_table.php | 57 ++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 app/Models/Pertanian/Petani.php create mode 100644 database/migrations/2026_06_26_180741_create_petani_master_table.php diff --git a/app/Models/Pertanian/Petani.php b/app/Models/Pertanian/Petani.php new file mode 100644 index 0000000..54668c2 --- /dev/null +++ b/app/Models/Pertanian/Petani.php @@ -0,0 +1,77 @@ + 'boolean', + 'tanggal_lahir' => 'date', + + 'pendidikan_terakhir' => Pendidikan::class, + 'status_perkawinan' => Pernikahan::class, + ]; + + public function getUmurAttribute(): ?int + { + if (!$this->tanggal_lahir) { + return null; + } + + return Carbon::parse($this->tanggal_lahir)->age; + } + + public function desaKelurahan(): BelongsTo + { + return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id'); + } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class, 'user_id'); + } +} diff --git a/database/migrations/2026_06_26_180741_create_petani_master_table.php b/database/migrations/2026_06_26_180741_create_petani_master_table.php new file mode 100644 index 0000000..6e3efed --- /dev/null +++ b/database/migrations/2026_06_26_180741_create_petani_master_table.php @@ -0,0 +1,57 @@ +id(); + $table->string('uid')->unique(); + + $table->string('nama'); + $table->boolean('jenis_kelamin'); + $table->string('tempat_lahir')->nullable(); + $table->date('tanggal_lahir'); + + $table->string('pendidikan_terakhir')->nullable(); + + $table->string('alamat')->nullable(); + $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan'); + + $table->string('nomor_telepon')->nullable(); + $table->string('foto', 500)->nullable(); + + $table->string('status_perkawinan')->nullable(); + + $table->string('kk')->nullable(); + $table->string('ktp')->nullable(); + + $table->string('path_kk', 500)->nullable(); + $table->string('file_kk')->nullable(); + $table->string('path_ktp', 500)->nullable(); + $table->string('file_ktp')->nullable(); + + $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null'); + $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null'); + $table->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null'); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('petanis'); + } +};