petani lahan dan skor
This commit is contained in:
@@ -15,6 +15,8 @@ use App\Models\Wilayah\DesaKelurahan;
|
||||
use App\Enums\Pendidikan;
|
||||
use App\Enums\Pernikahan;
|
||||
|
||||
use App\Models\Pertanian\SkorPetani;
|
||||
|
||||
class Petani extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
@@ -78,6 +80,28 @@ class Petani extends Model
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(function (Petani $petani) {
|
||||
|
||||
$skor = SkorPetani::where('petani_id')->orderBy('id')->first();
|
||||
if (!$skor) {
|
||||
$petaniUid = $petani->uid;
|
||||
$part = explode('-', $petaniUid);
|
||||
$skor = SkorPetani::create([
|
||||
'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)),
|
||||
'created_by' => $petani->created_by,
|
||||
'updated_by' => $petani->updated_by
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function skor(): HasOne
|
||||
{
|
||||
return $this->hasOne(SkorPetani::class, 'petani_id');
|
||||
}
|
||||
|
||||
public function praktikBudidaya(): HasOne
|
||||
{
|
||||
return $this->hasOne(PraktikBudidaya::class, 'petani_id')->latestOfMany();
|
||||
|
||||
Reference in New Issue
Block a user