How to Update Or Create - HasMany/BelongsTo (One to Many) relation
Please guide me on how to (update or create) student's previous academic record. I want to allow admin to add new academic record while updating the existing one as well that why I want to know about (createOrUpdate).
students Model
public function previous_academic_record()
{
return $this->hasMany(previous_academic_record::class);
}
previous_academic_record Model
public function students()
{
return $this->belongsTo(students::class);
}
createOrUpdate requires something to search for the student's record. If a model can be found with the search terms then the model is updated with the other fields. Otherwise a new record is created.
It is used where you don't know the ID for the record - because if you knew the ID then the record must exist and you can update it correctly.
But, no one can help you without an actual problem to be solved.