/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(TrainingFormRequest $request) { // $slug = uniqid(); $training = new Training(array('training_name' => $request->get('training_name'), 'training_type' => $request->get('training_type'), 'applying_information' => $request->get('applying_information'), 'objectives' => $request->get('objectives'), 'courses' => $request->get('courses'), 'start_date' => $request->get('start_date'), 'end_date' => $request->get('end_date'), 'provided_resources' => $request->get('provided_resources'), 'accommodation' => $request->get('accommodation'), 'testimonial' => $request->get('testimonial'), 'daily_schedule' => $request->get('daily_schedule'), 'fees_structure' => $request->get('fees_structure'), 'responsible_person' => $request->get('responsible_person'), 'training_slug' => $slug)); $training->save(); return redirect('/training_info')->with('status', 'Your Information have been inserted'); }
public function addTraining(Request $request) { $data = array('name' => htmlentities($request->input('title')), 'description' => htmlentities($request->input('description')), 'image' => $request->input('imagine'), 'areaType' => substr($request->input('arie'), 0, 1), 'area' => htmlentities(substr($request->input('arie'), 1)), 'locuri' => htmlentities($request->input('locuri')), 'ziua' => htmlentities($request->input('ziua')), 'ora' => htmlentities($request->input('ora'))); $data['intrebari'] = array(); $idIntrebare = 1; $intrebare = htmlentities($request->input('intrebare' . $idIntrebare)); while (isset($intrebare)) { array_push($data['intrebari'], $intrebare); $idIntrebare++; $intrebare = $request->input('intrebare' . $idIntrebare); } $rules = array('name' => 'required', 'description' => 'required', 'image' => 'image', 'area' => 'exists:areas,id', 'subarea' => 'exists:subareas,id', 'locuri' => 'numeric|required', 'ziua' => 'required', 'ora' => 'required'); if ($data['areaType'] == 's') { $data['subarea'] = $data['area']; $data['area'] = Subarea::where('id', $data['subarea'])->first()->area_id; } else { $data['subarea'] = ""; } $validator = Validator::make($data, $rules); if (!$validator->fails()) { $training = new Training(); $nameOfImage = $this->generateRandomString() . '.jpg'; Storage::put('images/' . $nameOfImage, $data['image']); $training->trainer_id = Auth::user()->id; $training->name = $data['name']; $training->description = $data['description']; $training->image = "images/" . $nameOfImage; $training->area_id = $data['area']; $training->subarea_id = $data['subarea']; $training->locuri = $data['locuri']; $training->save(); $group = new Group(); $group->trainer_id = Auth::user()->id; $group->training_id = $training->id; $group->area_id = $training->area_id; $group->subarea_id = $training->subarea_id; $group->groupOrder = 1; $group->data = $data['ziua']; $group->ora = $data['ora']; $group->save(); foreach ($data['intrebari'] as $intrebare) { $question = new Question(); $question->training_id = $training->id; $question->question = $intrebare; $question->posted_by = Auth::user()->id; $question->required = 1; $question->save(); } return redirect('/trainer'); } else { return $data['areaType']; } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(TrainingFormRequest $request) { $exercise_fields = ['exercise_id', 'reps', 'series', 'duration']; $exercise_data = []; $training = new Training(); $training->user_id = Auth::user()->id; $training->save(); foreach ($exercise_fields as $field) { $data = $request->input($field); foreach ($data as $key => $value) { $exercise_data[$key][$field] = $value; } } $user_id = Auth::user()->id; foreach ($exercise_data as &$exercise) { $exercise['user_id'] = $user_id; } $training->exercises()->attach($exercise_data); return response()->json(array('success' => true)); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(TrainingFormRequest $request) { $ImageExtensions = array('jpg', 'png', 'jpeg'); $input = $request->all(); if (isset($input['image_path'])) { $Image = $input['image_path']; $ImageExtension = $request->file('image_path')->getClientOriginalExtension(); if (in_array($ImageExtension, $ImageExtensions)) { $Image = $this->imageUpload($Image); $input['image_path'] = $Image; } else { return redirect('/training_info')->with('warning', 'Only jpg, png and jpeg image format are allowed.'); } } else { $input['image_path'] = "training_image/default.gif"; } $training = new Training(array('training_name' => $request->get('training_name'), 'training_type' => $request->get('training_type'), 'description' => $request->get('description'), 'applying_information' => $request->get('applying_information'), 'objectives' => $request->get('objectives'), 'start_date' => $request->get('start_date'), 'end_date' => $request->get('end_date'), 'provided_resources' => $request->get('provided_resources'), 'accommodation' => $request->get('accommodation'), 'daily_schedule' => $request->get('daily_schedule'), 'fees_structure' => $request->get('fees_structure'), 'responsible_person' => $request->get('responsible_person'), 'image_path' => $input['image_path'])); $training->save(); return redirect('/training_info')->with('status', 'Your information is inserted successfully.'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(TrainingFormRequest $request) { $training = new Training(array('training_name' => $request->get('training_name'), 'training_type' => $request->get('training_type'), 'description' => $request->get('description'), 'applying_information' => $request->get('applying_information'), 'objectives' => $request->get('objectives'), 'start_date' => $request->get('start_date'), 'end_date' => $request->get('end_date'), 'provided_resources' => $request->get('provided_resources'), 'accommodation' => $request->get('accommodation'), 'daily_schedule' => $request->get('daily_schedule'), 'fees_structure' => $request->get('fees_structure'), 'responsible_person' => $request->get('responsible_person'))); $training->save(); return redirect('/training_info')->with('status', 'Your information is inserted successfully.'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(TrainingFormRequest $request) { $training_name = $request->get('training_name'); $start_date = $request->get('start_date'); $end_date = $request->get('end_date'); $check = Training::whereTraining_name($training_name)->count('id'); if ($check) { return redirect('/training_info')->with("check", $training_name . " Training Has Already Entered."); } else { if ($start_date > $end_date) { return redirect('/training_info')->with("checkDuration", "Start Time Should Not Be Greater Than End Date."); } $ImageExtensions = array('jpg', 'png', 'jpeg', 'gif', 'tif', 'tiff', 'bmp'); $input = $request->all(); if (isset($input['image_path'])) { $Image = $input['image_path']; $ImageExtension = $request->file('image_path')->getClientOriginalExtension(); if (in_array($ImageExtension, $ImageExtensions)) { $Image = $this->imageUpload($Image); $input['image_path'] = $Image; } else { return redirect('/training_info')->with('warning', 'Only jpg, png, tif, tiff, bmp and jpeg Image Format Are Allowed.'); } } else { $input['image_path'] = "training_image/default.gif"; } $training = new Training(array('training_name' => $request->get('training_name'), 'training_type' => $request->get('training_type'), 'description' => $request->get('description'), 'applying_information' => $request->get('applying_information'), 'objectives' => $request->get('objectives'), 'start_date' => Carbon\Carbon::createFromFormat('Y-m-d', $request->get('start_date')), 'end_date' => Carbon\Carbon::createFromFormat('Y-m-d', $request->get('end_date')), 'provided_resources' => $request->get('provided_resources'), 'accommodation' => $request->get('accommodation'), 'daily_schedule' => $request->get('daily_schedule'), 'fees_structure' => $request->get('fees_structure'), 'responsible_person' => $request->get('responsible_person'), 'image_path' => $input['image_path'])); $training->save(); return redirect('/training_info')->with('status', 'Your Information Is Inserted Successfully.'); } }