public function store(Request $request, $id) { $orgOrder = OrganizationOrder::findOrFail($id); $lineItem = new LineItem(); $lineItem->organization_order_id = $id; if ($request->input('UserOrder') && strlen($request->input('UserOrder')['order']) > 0) { if ($request->input('UserOrder')['default'] == 1) { UserOrder::where('user_id', '=', $request->user()->id)->where('restaurant_id', '=', $orgOrder->restaurant()->id)->where('default', '=', '1')->update(['default' => 0]); } $userOrder = new UserOrder(); $userOrder->fill($request->input('UserOrder')); $userOrder->user_id = $request->user()->id; $userOrder->restaurant_id = $orgOrder->restaurant()->id; $userOrder->save(); $lineItem->user_order = $userOrder->id; } else { $lineItem->user_order = $request->input('LineItem')['user_order']; } if ($lineItem->isValid()) { $lineItem->save(); return redirect()->route('orgorder.show', ['orgId' => $orgOrder->organization()->id, 'id' => $lineItem->organization_order_id]); } else { return redirect()->route('lineitem.create', ['id' => $id])->withErrors($lineItem->getErrors())->withInput(); } }
public function makeDefault(Request $request) { $this_order = UserOrder::find($request->id); $restaurant_id = $this_order->restaurant_id; $user_orders = UserOrder::orderBy('id')->get(); foreach ($user_orders as $user_order) { if ($user_order->restaurant_id == $restaurant_id) { $user_order->default = $user_order->id == $request->id ? 1 : 0; $user_order->save(); } } return redirect()->route('user_orders.index', array('restaurant' => $restaurant_id)); }
public function store(Request $request) { $user_order = new \App\UserOrder(); $user_order->fill($request->input('UserOrder', [])); $user_order->user_id = $request->user()->id; if (!isset($user_order->default)) { $user_order->default = 0; } else { $user_orders = UserOrder::orderBy('id')->get(); foreach ($user_orders as $this_order) { if ($this_order->restaurant_id == $user_order->restaurant_id) { $this_order->default = 0; $this_order->save(); } } } if ($user_order->isValid()) { $user_order->save(); return redirect()->route('user_orders.index'); } else { return redirect()->route('user_orders.create')->withErrors($user_order->getErrors())->withInput(); } }
public function run() { Artisan::call('migrate:refresh'); $user = \App\User::create(['email' => '*****@*****.**', 'password' => '$2y$10$zhRDGljo5k5jn6oifVCA7.4GzB6OKmV1QkJfvErtcheR0m5jMLK9S', 'firstName' => 'ftesting1', 'lastName' => 'ltesting1']); $restaurant = \App\Restaurant::create(['name' => 'Burger King']); $organization = \App\Organization::create(['name' => 'Testing1']); $poll = \App\Poll::create(['closed_at' => '2017-05-18 03:00:00', 'closed_by' => '2017-05-18 04:00:00', 'organization_id' => 1]); $organization->restaurants()->save($restaurant); $poll->restaurants()->save($restaurant); $role = \App\Role::create(['user_id' => 1, 'organization_id' => 1, 'role' => 'Tester']); $organization_order = \App\OrganizationOrder::create(['organization_restaurant_id' => 1, 'due_by' => '2017-05-18 04:00:00', 'closed_at' => '2017-05-18 03:00:00']); $user_order = \App\UserOrder::create(['user_id' => 1, 'restaurant_id' => 1, 'default' => 1, 'order' => 'Test Burger']); $polloption = \App\PollRestaurant::find(1); $polloption->users()->save($user); }