model petani
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Pertanian;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
use App\Models\Wilayah\DesaKelurahan;
|
||||||
|
use App\Enums\Pendidikan;
|
||||||
|
use App\Enums\Pernikahan;
|
||||||
|
|
||||||
|
class Petani extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected $table = 'petani';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'uid',
|
||||||
|
'nama',
|
||||||
|
|
||||||
|
'telepon',
|
||||||
|
'alamat',
|
||||||
|
|
||||||
|
'kk',
|
||||||
|
'ktp',
|
||||||
|
'uid',
|
||||||
|
'desa_kelurahan_id',
|
||||||
|
|
||||||
|
'foto',
|
||||||
|
|
||||||
|
'path_kk',
|
||||||
|
'file_kk',
|
||||||
|
'path_ktp',
|
||||||
|
'file_ktp',
|
||||||
|
|
||||||
|
'jenis_kelamin',
|
||||||
|
'tempat_lahir',
|
||||||
|
'tanggal_lahir',
|
||||||
|
'pendidikan_terakhir',
|
||||||
|
'status_perkawinan',
|
||||||
|
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
'deleted_by'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'jenis_kelamin' => '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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?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('petani', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user