/** * Store a newly created resource in storage. * * @return Response */ public function store() { $new_promo = $this->request->all(); $new_promo['business_afm'] = \Auth::user()->afm; $promo = Promotion::create($new_promo); return \Redirect::route('business.promotions'); }
public function run() { DB::table('promotions')->delete(); Promotion::create(['nom' => 'SI3']); Promotion::create(['nom' => 'SI4']); Promotion::create(['nom' => 'SI5']); Promotion::create(['nom' => 'MAM3']); Promotion::create(['nom' => 'MAM4']); Promotion::create(['nom' => 'MAM5']); Promotion::create(['nom' => 'BAT3']); Promotion::create(['nom' => 'BAT4']); Promotion::create(['nom' => 'BAT5']); Promotion::create(['nom' => 'ELEC3']); Promotion::create(['nom' => 'ELEC4']); Promotion::create(['nom' => 'ELEC5']); Promotion::create(['nom' => 'GE3']); Promotion::create(['nom' => 'GE4']); Promotion::create(['nom' => 'GE5']); Promotion::create(['nom' => 'GB3']); Promotion::create(['nom' => 'GB4']); Promotion::create(['nom' => 'GB5']); Promotion::create(['nom' => 'CIP1']); Promotion::create(['nom' => 'CIP2']); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(PromotionRequest $request) { $input = $request->all(); Promotion::create($input); return redirect('promotion'); }
public function postNewPromotion(Request $request) { $this->validate($request, ['name' => 'required|max:50', 'discount' => 'required|numeric|min:1|max:100', 'type' => 'required|numeric|min:1|max:100', 'image' => 'image', 'promo_date' => 'max:23']); //create a new promotion $promotion = Promotion::create(['name' => $request->name, 'discount' => $request->discount, 'type' => $request->type, 'description' => $request->description]); //process dates if (!empty($request->promo_date)) { $dates = explode(" - ", $request->promo_date); $promotion->start_date = DateTime::createFromFormat('m/d/Y', $dates[0])->format('Y-m-d'); $promotion->end_date = DateTime::createFromFormat('m/d/Y', $dates[1])->format('Y-m-d'); //check if promotion is activated on create if ($dates[0] <= new DateTime("now") && $dates[1] > new DateTime("now")) { $promotion_status = 1; } else { $promotion_status = 0; } } if (Input::hasFile('image')) { $file = Input::file('image'); $imagename = 'promotion_' . $promotion->id . '.' . Input::file('image')->getClientOriginalExtension(); $file->move('uploads', $imagename); $promotion->image = $imagename; } $promotion->save(); //attach promotion to selected items $cruises = Input::get('cruises'); $cabins = Input::get('cabins'); $amenities = Input::get('amenities'); if (!empty($cruises)) { foreach ($cruises as $key => $val) { $cruise = Cruise::find($val); $cruise->promotion_id = $promotion->id; $cruise->save(); } } else { if (!empty($cabins)) { foreach ($cabins as $key => $val) { $cabin = Cabin::find($val); $cabin->promotion_id = $promotion->id; $cabin->save(); } } else { if (!empty($amenities)) { foreach ($amenities as $key => $val) { $amenity = Amenity::find($val); $amenity->promotion_id = $promotion->id; $amenity->save(); } } } } return redirect('/admin/promotion/' . $promotion->id)->with('status', 'Promotion created!'); }