enter image description herei have 3 tables made in Voyager and with BREAD (news - catg - news_catg). My 'news' Table have Relationship (Belongs To Many) to 'catg' and the news_catg is the pivot table Every think is working will except the Delete i have to Delete the Records manually from the pivot table it should be automatic like add and update
Asked
Active
Viewed 589 times
0
-
why you need to delete data manually, don't you have casecade delete? – Prafulla Kumar Sahu May 16 '19 at 17:01
-
please share your migration files codes – Prafulla Kumar Sahu May 16 '19 at 18:52
-
its working for add and update for ex: i add 1 news with 3 catg its working and the update too but the delete :( – Djhasan AboAli May 16 '19 at 18:52
-
With out looking at your table structure and indexing how I will say something? – Prafulla Kumar Sahu May 16 '19 at 18:56
-
all my migration files ? – Djhasan AboAli May 16 '19 at 18:56
-
Only pivot table migration. – Prafulla Kumar Sahu May 16 '19 at 18:57
-
i shared photo off my news_catg table i could not finde migration file for it – Djhasan AboAli May 16 '19 at 19:06
-
i made my tables with Voyager so i did not make any migration file – Djhasan AboAli May 16 '19 at 19:09
-
check laravel documentation for many to many relationships, to understand correct table structure and expected behaviour. – Prafulla Kumar Sahu May 16 '19 at 19:10
2 Answers
1
finally i found that there is bug in Voyager and there is no way to fix this issue from the admin panel so i did the flowing :
1 - deleted the Pivot table .
2- create new migration file in my app
3 -
` Schema::create('Relation table name', function (Blueprint $table) {
$table->integer('first table id')->unsigned();
$table->foreign('first table id')->references('id')
->on('first table')->onDelete('cascade');
$table->integer('second table id')->unsigned();
$table->foreign('second table id')->references('id')->on('second table');
});`
Relation table name should be like :secondtablename_firsttablename for ex : catgs_news or it wont work !!! and the first table id should be tablename_id like news_id
4- then you go to voyager and it will work but you have to edit the new table and add timestamps and you dont have to make bread for it

Djhasan AboAli
- 11
- 2
0
You can use the detach() function to delete data from pivot table.

Mehrad Malayeri
- 41
- 5
-
ok but where do i have to put the detach() function with this voyager – Djhasan AboAli May 16 '19 at 19:15