laravel-and-vue.js-spa-Recipe-Box icon indicating copy to clipboard operation
laravel-and-vue.js-spa-Recipe-Box copied to clipboard

Delete all not updated against sync()

Open Siebov opened this issue 6 years ago • 2 comments

Hello. You are using

RecipeIngredient::whereNotIn('id',$ingredients_updated)
            ->where('recipe_id',$recipe->id)
            ->delete();

        RecipeDirection::whereNotIn('id',$directions_updated)
            ->where('recipe_id',$recipe->id)
            ->delete();

and why not just

$recipe->ingredients()->sync($ingredients_updated);
$recipe->directions()->sync($directions_updated);

insted?

Siebov avatar Jan 30 '18 21:01 Siebov

@Sebbba i didnt know about this. Are you sure this works? I will test this later

anishdcruz avatar Jan 31 '18 04:01 anishdcruz

@anishdcruz https://laravel.com/docs/5.5/eloquent-relationships Syncing Associations - chapter.

Siebov avatar Jan 31 '18 09:01 Siebov