Skip to main content

Recipe extends Model

class Recipe extends Model
{
   public function ingredients()
    {
        return $this->belongsToMany('AppIngredient');
    }
}
     
class Ingredient extends Model
    {
       public function recipes()
        {
            return $this->belongsToMany('AppRecipe');
        }
    }
     
$new_recipe = Recipe::create(["name" => "my_recipe","description" => "very tasty"]);
     
$new_recipe->ingredients()->sync($arr_ingredients);