public function processOndayForm(Request $request) { $messages = array('different' => 'Origin location and destination location cannot be same'); $this->validate($request, ['cost' => 'required|numeric', 'fare' => 'required|numeric', 'market_price' => 'required|numeric', 'location_id_origin' => 'different:location_id_destination'], $messages); $onday = new Onday(); $onday->type = $request->input('type'); $onday->activity_id = $request->input('activity_id'); $onday->location_id_origin = $request->input('location_id_origin'); $onday->customer_id = $request->input('customer'); $onday->location_id_destination = $request->input('location_id_destination'); $onday->cost = $request->input('cost'); $onday->fare = $request->input('fare'); $onday->market_price = $request->input('market_price'); $onday->save(); $activity = Activity::findOrFail($request->input('activity_id')); $activity->comment = $request->input('comment'); $activity->save(); //adding onday other costs $other_cost = $request->input('other_cost'); foreach ($other_cost as $key => $value) { if ($value) { $onday_other_cost = OndayOtherCost::create(['cost' => $value]); $onday_other_cost->onday_id = $onday->id; $onday_other_cost->onday_other_cost_item_id = $key; $onday_other_cost->save(); $onday->cost = $onday->cost + $value; $onday->save(); } } return redirect()->route('home'); }
public function destroy($id) { $activity = Activity::find($id); $activity->delete(); $nil = Nil::where('activity_id', '=', $id)->get(); if ($nil->count() > 0) { $nil->pop()->delete(); } $maintenance = Maintenance::where('activity_id', '=', $id)->get(); if ($maintenance->count() > 0) { $maintenance->pop()->delete(); } $onday = Onday::where('activity_id', '=', $id)->get(); if ($onday->count() > 0) { $onday->pop()->delete(); } return redirect()->back(); }