[eluser]North2Alaska[/eluser]
[quote author="Andy78" date="1334240557"]Based on the structure in the diagram how would I go about creating an order which has multiple food items in it and is related to a specific user and from a specific takeaway. How would I structure the save for all that in my controller?
[/quote]
Code:
$order = new Order();
// Add other order information
$food = new Food();
$food->where('food_name', 'hamburger')->get();
$order->save($food);
$food = new Food();
$food->where('food_name', 'Soda')->get();
$order->save($food);
$food = new Food();
$food->where('food_name', 'French Fries')->get();
$order->save($food);
WanWizard may be able to tell us a way using an array and do the save all at once. But this is what I am doing now.
I just thought of something else:
Code:
$order = new Order();
// Add other order information
$foods = array('hamburger', 'French Fries', 'Soda');
$food = new Food();
$food->where_in('food_name', $foods)->get();
$order->save($food->all);
That may work.