Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     setlocale(LC_TIME, 'ru_RU.CP1251', 'rus_RUS.CP1251', 'Russian_Russia.1251');
     //        dd($request);
     $schedule = Schedule::create($request->except('owner_id', 'q'));
     $date = $request->date;
     $string = $request->extra;
     //        dd($string);
     $new_string2 = array();
     $new_string = preg_split('/[\\r\\n#]+/', $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     foreach ($new_string as $new_string1) {
         if (!ctype_space($new_string1)) {
             $new_string2[] = $new_string1;
         }
     }
     $program = array();
     if ($new_string2) {
         for ($i = 0; $i < count($new_string2); $i++) {
             for ($j = 0; $j < count($new_string2); $j++) {
                 if ($j % 2 == 0) {
                     $program = array_add($program, $j / 2, ['time' => $new_string2[$j], 'name' => $new_string2[$j + 1]]);
                 }
             }
         }
     }
     $jsonProgram = json_encode($program);
     $schedule->date = $date;
     $schedule->program = $jsonProgram;
     $schedule->extra = $string;
     $schedule->save();
     return redirect()->route('admin.schedule.index');
 }