mercredi 17 avril 2019

Why are multiple rows ('versions') saved with eloquent, when I only edit one

I use a 'version' system to save multiple versions of a 'minor'. It contains quite a few fields, like name, goals, requirements, subject and many more. When I save 'version 2', using eloquent, it also changes the other version.

I have tried multiple ways of saving the minor, but every time it creates the same error.

Minor::limit(1)
            ->where("id", $id)
            ->where('version', $_POST['version'])
            ->first()
            ->update([
                'name' => $_POST['name'],
                'ects' => floatval($_POST['ects']),
                'contact_hours' => intval($_POST['contact_hours']),
                'education_type' => $_POST['education_type'],
                'language' => $_POST['language'],
                'subject' => Input::get('subject'),
                'goals' => Input::get('goals'),
                'requirements' => Input::get('requirements'),
            ]);

It should only save the selected version, but instead, it overwrites every version of the selected minor and saves them all. How can I prevent this, or does anyone have an idea on how to fix this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire