Default values on pivot table for attach/save

Hi, is there any way to set default values for the pivot table for attach and save? So rather than having to write

Foo::things()->attach(2, ['bar' => 'baz']);

every time when 'bar' == 'baz' most of the time, is there any way to set bar to baz by default if it's not set? I tried overriding the attach() method in the model, but then realized I can't do that since the attach() method is in the relationship class, not the Model class. Is there anywhere the attach() method can be extended/overriden or where default values can be set?


dtaub-mms replied 3 years ago

Sorry to bump, but would anyone know if this is at least possible in theory (without modifications to the framework)?

kduszczy replied 1 year ago

I don't know if this is still actual but you can set default values on your database, and just leave this empty.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us