-
Notifications
You must be signed in to change notification settings - Fork 28
[Proposal] Default values on pivot table #872
Comments
Is there any to set default value of additional attributes??
like default attributes on Model
|
Why is it closed? This proposal wasn't implemented. It is still impossible to specify default attributes for a |
my case:
All OK until here. Now, i have some polimorphic relations, and i cant do a because it dont call the constructor method, and i receive this exception: General error: 1364 Field 'uuid' doesn't have a default value (SQL: insert into ...... Workaround ?? I like to use attach / sync / and variations on my polimorfic relations... |
I'd also like to be able to set a default value on a custom pivot. I like @zohaibhassan156's suggestion. |
Same here, can we have it like @zohaibhassan156's suggestion? |
When you define a Many-To-Many relationship in your model, you can use
wherePivot
method for filtering it.Some people use this feature, and create relationships like these in models:
But when you save relationship you still have to set pivot data:
$club->admins()->save($user, ['is_admin' => 1]);
I think, it confusing at first sight, and a little tedious because you always need to define pivot data if it different from default table values.
And I didn't find the way to set default pivot values on Many-To-Many relationship in documentation actually.
Also, some people(link, link) asked how to do it, but they didn't get the answer.
So my proposal is to allow to define default pivot values, which will be used both for filtering and for saving:
Something like this:
$this->belongsToMany(User::class)->pivotValues(['is_admin' => 1]);
The text was updated successfully, but these errors were encountered: