eggplantSword's avatar

createMany not working, nothing happens

Why isn't this working?

I removed all the charts except for the first one, but each one has a different amount, after I set them I have a dd($profile) but surveyCharts is always empty. Why isn't it getting saved?

0 likes
3 replies
Snapey's avatar

Is $profile saved to the database?

Mass assignment issue? Have you set guarded or fillable?

Are you using transaction?

Try removing all queries when assembling data, and put simple text string or integer in their places

Examine the actual tables.

eggplantSword's avatar

@Snapey mmmmmmmmm $profile is saved, I do have fillable set, but I am using transaction. The "full" code goes something like this

   public function store(Request $request)
    {
        DB::beginTransaction();

        try {
            resolve(SurveyRequest::class);

            $surveyService = new SurveyService('profile');
            $profile = $surveyService->write($request->merge(['dummy_module_id' => DummyModule::profiles()->value('id')])->all());

            ///snipped of code above

            dd('commit', $profile);

            DB::commit();

            return redirect('profiles/profile')->with('success', 'Perfil registrado correctamente.');
        } catch (\Illuminate\Validation\ValidationException $e) {
            DB::rollBack();

            return back()->withErrors($e->errors());
        } catch (\Exception $e) {
            Log::error($e);
            DB::rollBack();

            return back()->withErrors('Hubo un error al intentar registrar el Perfil.', 'notification');
        }
    }

Maybe I'm wrong but if $profile is saved here since I do see it and it even has an id I thought the charts would also get saved and displayed in the dd but they don't. I have saved things to this table before.

Edit: I removed the dd and dump and it said correct but again nothing actually got saved

Snapey's avatar

@eggplantSword remove the transaction and see what happens.

If somthing errors inside the code, the data, correctly written to the DB will be lost as the transaction is rolled back

Please or to participate in this conversation.