Chron
2 months ago
184
1
Laravel

General error: 1364 Field column_id doesn't have a default value

Posted 2 months ago by Chron

Is there a way to add an additional value in a sync many to many?

I tried this but I'm getting General error: 1364 Field column_id doesn't have a default value error:

 $foo = Foo::where('name', $request['foo'])->first();

            foreach ($request['bars'] as $k => $bar) {
                $bars[$k] = Bar::firstOrCreate([
                    'name' => $bar
                ]);

                $user->bars()->sync([$bars[$k]->id, ['foo_id' => $foo->id]]);
	}

Please sign in or create an account to participate in this conversation.