webpatser/laravel-uuid

UUID on Many to Many Relationship

faozimipa opened this issue · 2 comments

I have created a trait and applied it to my model. But in other side, How to solve the problem of making uuid in many to many relationship, where we do not make model many to many table?

Example : we have two model User and Role and we have three tables users , roles and user_role.
we have sync code bellow.
$create = $user->roles()->sync($roles_id);
we get $create with id = '' how to solve the problem?

See https://laravel.com/docs/5.5/eloquent-relationships#many-to-many

In addition to customizing the name of the joining table, you may also customize the column names of the keys on the table by passing additional arguments to the belongsToMany method. The third argument is the foreign key name of the model on which you are defining the relationship, while the fourth argument is the foreign key name of the model that you are joining to:

return $this->belongsToMany('App\Role', 'role_user', 'user_id', 'role_id');

The problem is id on user_role is always null,
Note I use trait uuids