thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.77k stars 2.67k forks source link

many to many relationship #1354

Closed mohammed-elattar closed 7 years ago

mohammed-elattar commented 7 years ago

I made all steps like in the documentation but i can't get multiple select field and these is the steps in pics , please help me to sort it out

voyager5 voyager1 voyager2 voyager3 voyager4

nunomsh commented 7 years ago

the function name must match the field name

public function categoryId()
{
    return $this->belongsToMany(Category::class);
}

From documentation: "Note: the method used for this relationship, must match the camelCase version of the row from the pages table. "

plus you don't need the "image_category" in the model. This is used to relationship 1-to-1, not 1-to-N (I think...) Voyager will store the relation in a pivot table, that will relate both tables, and it's usually the name of both tables combined (singular) So try to create a table with the name categorie_image with 2 columns only: image_id and category_id

lancepioch commented 7 years ago

Labels: question

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.