I have a Meal model that can contain an Ingredient model and Ingredient has many properties ...
I have all the ingredients in the DB, as well as some dishes ....
But I want to create a new food, but without storing it in the database.
so something like:
$meal = new Meal; $meal->ingredients()->attach(5);
where 5 is the identifier of the ingredient in the database.
However, this will not work, because $ food is not stored in the DB and the attach () function is trying to create a new entry in the meal_ingredient table ....
So, is there a way to create an "autonomous" model and connect it to the "online" data?
thanks
source share