public function conocenos() { $galerias = \App\galeria::select('id_tipo_galeria as id')->get(); $datos = array(); foreach ($galerias as $val) { $datos[] = $val->id; } return view('public/conocenos', ['categorias' => \DB::table('tipo_galeria')->select('id_tipo_galeria as id', 'nombre')->where('activo', '=', 1)->whereIn('tipo_galeria.id_tipo_galeria', $datos)->get()]); }
public function update(Request $request) { // dd($request->file()); $id = $request->id_galeria; $archivos = $request->hasFile('imagenes') ? $request->file('imagenes') : FALSE; if ((int) $id > 0 && is_array($archivos)) { foreach ($archivos as $val) { $archivo = $val; $ext = strtolower($archivo->getClientOriginalExtension()); if ($ext == "jpg" || $ext == 'jpeg' || $ext == "png") { $carpeta = \App\galeria::select(\DB::raw('CONCAT(nombre,id_galeria) as nombre'))->find($id); $carpeta = $carpeta->nombre; $carpeta = str_replace(" ", "_", '/assets/images/' . $carpeta . '/'); if (!file_exists(getcwd() . $carpeta)) { mkdir(getcwd() . $carpeta, 0777, true); } $str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; do { $nombre = ""; for ($i = 0; $i <= 15; $i++) { $nombre .= substr($str, rand(0, strlen($str) - 1), 1); } $nombre2 = $nombre . "_2." . $ext; $nombre .= "." . $ext; } while (file_exists(getcwd() . $carpeta . $nombre)); if ($archivo->move(getcwd() . $carpeta, $nombre)) { $data[] = array('id_galeria' => $id, 'tipo_elemento' => 1, 'url' => $carpeta . $nombre); switch (mb_strtolower($ext)) { case 'jpg': $imagen = imagecreatefromjpeg(getcwd() . $carpeta . $nombre); $imagesize = getimagesize(getcwd() . $carpeta . $nombre); $width = $imagesize[0]; $heigth = $imagesize[1]; $factor = $width / 1024; $width = $width / $factor; $heigth = (int) ($heigth / $factor); $imagesave = imagescale($imagen, $width, $heigth); imagejpeg($imagesave, getcwd() . $carpeta . $nombre2, 95); imagedestroy($imagesave); imagedestroy($imagen); break; case 'jpeg': $imagen = imagecreatefromjpeg(getcwd() . $carpeta . $nombre); $imagesize = getimagesize(getcwd() . $carpeta . $nombre); $width = $imagesize[0]; $heigth = $imagesize[1]; $factor = $width / 1024; $width = $width / $factor; $heigth = (int) ($heigth / $factor); $imagesave = imagescale($imagen, $width, $heigth); imagejpeg($imagesave, getcwd() . $carpeta . $nombre2, 95); imagedestroy($imagesave); imagedestroy($imagen); break; case 'png': $imagen = imagecreatefrompng(getcwd() . $carpeta . $nombre); $imagesize = getimagesize(getcwd() . $carpeta . $nombre); $width = $imagesize[0]; $heigth = $imagesize[1]; $factor = $width / 1024; $width = $width / $factor; $heigth = (int) ($heigth / $factor); $imagesave = imagescale($imagen, $width, $heigth); imagejpeg($imagesave, getcwd() . $carpeta . $nombre2, 95); imagedestroy($imagesave); imagedestroy($imagen); break; } } } } if (\DB::table('elemento')->insert($data)) { $galeria = \App\galeria::find($id); $galeria->step = 4; $galeria->save(); } } }