skor petani praktik budidaya
This commit is contained in:
@@ -44,6 +44,30 @@ class SurveyPanen extends Model
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(function (SurveyPanen $survey) {
|
||||
|
||||
$petani = Petani::find($survey->petani_id);
|
||||
$skor = SkorPetani::where('petani_id', $petani->id)->orderBy('id')->first();
|
||||
if (!$skor) {
|
||||
$petaniUid = $petani->uid;
|
||||
$part = explode('-', $petaniUid);
|
||||
$skor = SkorPetani::create([
|
||||
'petani_id' => $petani->id,
|
||||
'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)),
|
||||
'created_by' => $petani->created_by,
|
||||
'updated_by' => $petani->updated_by
|
||||
]);
|
||||
}
|
||||
|
||||
$skor->update([
|
||||
'skor_d2_k3_1_penentuan_pematangan' => $survey->dasar_penentuan_panen,
|
||||
'skor_d2_k3_5_sortasi_awal_pemisahan_kualitas' => $survey->praktik_sortasi,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function petani(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Petani::class, 'petani_id');
|
||||
|
||||
Reference in New Issue
Block a user