/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::except('linha'); $validation = Validator::make($input, Matriz::$rules); if ($validation->passes()) { $nome_mat = Input::get('nome_mat'); $matriz = DB::table('matriz_mat')->select(DB::raw('id'))->where('nome_mat', '=', $nome_mat)->get(); if (sizeof($matriz) == 0) { $this->matrizMat->create($input); $matriz = DB::table('matriz_mat')->select(DB::raw('id'))->where('nome_mat', '=', $nome_mat)->get(); } $all = Input::all(); foreach ($all['linha'] as $row) { if (!isset($row['ofertar'])) { $row['ofertar'] = '1'; } else { if ($row['ofertar'] == 'false') { $row['ofertar'] = '1'; } else { $row['ofertar'] = '0'; } } if (sizeof($row) <= 4) { $row['semana'] = ''; $row['turno'] = ''; $row['predio'] = ''; $row['sala'] = ''; $row['professor'] = '0'; } else { if ($row['semana'] == 'null') { $row['semana'] = ''; } if ($row['turno'] == 'null') { $row['turno'] = ''; } if ($row['predio'] == 'null') { $row['predio'] = ''; } if ($row['sala'] == 'null') { $row['sala'] = ''; } } foreach ($matriz as $mat) { $temp = (array) $mat; $row['id_matriz'] = $temp['id']; } DB::table('matriz_sem')->insert($row); } return Redirect::route('admin.matriz.index'); } else { return Redirect::to('/admin/matriz/adicionar')->withInput()->withErrors($validation)->with('message', 'Preencha todos os Campos!'); } }