Closed neway02 closed 2 years ago
CategoryController
$category = Category::create();
$category->translations()->attach(1, ['title' => 'Тест 1']);
CategoryModel
public function translations()
{
return $this->belongsToMany(Language::class, 'category_language', 'category_id', 'language_id')
->as('translate')
->withPivot('title', 'slug');
}
I've not tried this myself, but I suspect you'd need to use a custom pivot model and that pivot model would need to implement the Sluggable package.
Thanks for the answer. I was hoping that this way of working has already been used by someone. But it's not a problem. Thanks again
If anyone needs to find a solution to use the module along with a pivot table.
Hi. Thank you very much for this package. Is it possible to make a slug in a pivot table? I have a Categories table and a Languages table. I have a pivot table category_language where I store category translations. It contains id, category_id, language_id, title, slug attributes. I'd like to automatically title the slug in this pivot table when I save Category model. Any ideas for this?