i have two table widget and page_widget
PageWidget model:
protected $fillable = [
'page_id',
'widget_codes',
'created_by',
'updated_by',
'deleted_by',
'deleted_at'
];
relation in this model:
public function widgets() {
return $this->belongsToMany(Widget::class, null, 'page_widget_ids',
'widget_codes');
}
widget model:
protected $fillable = [
'name',
'code',
'type',
'page_widget_ids',
'created_by',
'deleted_by',
'deleted_at'
];
on time of store i have to sync widget_code, and i use like this:
$pageWidget->widgets()->sync($input['widget_codes']);
it's doesn't work because in widget model it default primary key considered _id column and i want to give relation with code column
i try $primaryKey = 'code' in widget model but i'cant use this because widget model's other relation use with _id column.