Beispiel #1
0
 function store(Request $request)
 {
     $input = $request->all();
     $testArr = array();
     $files = $request->file('test_files');
     $getParam = Parameter::where('name', '=', $input['parameter'])->first();
     if (!empty($getParam)) {
         $testArr['parameter_id'] = $getParam->id;
     } else {
         $parameter = new Parameter();
         $parameter->create(array('name' => $input['parameter']));
         $testArr['parameter_id'] = DB::getPdo()->lastInsertId();
     }
     $getState = Parameter::where('name', '=', $input['state'])->first();
     if (!empty($getState)) {
         $testArr['state_id'] = $getState->id;
     } else {
         $state = new State();
         $state->create(array('name' => $input['state']));
         $testArr['state_id'] = DB::getPdo()->lastInsertId();
     }
     $getMethod = Method::where('name', '=', $input['method'])->first();
     if (!empty($getMethod)) {
         $testArr['method_id'] = $getMethod->id;
     } else {
         $method = new Method();
         $method->create(array('name' => $input['method']));
         $testArr['method_id'] = DB::getPdo()->lastInsertId();
     }
     $getTestMethod = TestMethod::where('name', '=', $input['test_method'])->first();
     if (!empty($getTestMethod)) {
         $testArr['test_method_id'] = $getTestMethod->id;
     } else {
         $tmethod = new TestMethod();
         $tmethod->create(array('name' => $input['test_method']));
         $testArr['test_method_id'] = DB::getPdo()->lastInsertId();
     }
     $checkTest = Test::where('parameter_id', '=', $testArr['parameter_id'])->where('parameter_id', '=', $testArr['state_id'])->where('parameter_id', '=', $testArr['method_id'])->where('parameter_id', '=', $testArr['test_method_id'])->first();
     if ($checkTest) {
         $test_id = $checkTest->id;
         Session::flash('flash_message', 'Test already exist.');
     } else {
         $testArr['price'] = $input['price'];
         $test = new Test();
         $test::create($testArr);
         $test_id = DB::getPdo()->lastInsertId();
         Session::flash('flash_message', 'Test created successfully.');
     }
     if ($test_id) {
         if (!empty($files[0])) {
             foreach ($files as $file) {
                 $fileName = $file->getClientOriginalName();
                 $file->move(public_path() . '/TestFiles/' . $test_id, $fileName);
                 $file = new TestFile();
                 $file::create(array('file_name' => $fileName));
             }
         }
         DB::table('test_processes')->where('test_id', '=', $test_id)->delete();
         if ($request->has('test_item')) {
             $items = $request->get('test_item');
             foreach ($items as $key => $value) {
                 $process = new Process();
                 $process::create(array('test_id' => $test_id, 'item_id' => $value, 'status' => 1));
             }
         }
     }
     Session::flash('flash_type', 'alert-success');
     return redirect('admin/tests');
 }