Esempio n. 1
0
 public static function GuardarFotos(Request $request)
 {
     $files = $request->file('file');
     $path = public_path() . '/imagenes/';
     if ($files != null) {
         if (!File::exists($path)) {
             File::makeDirectory($path);
         }
         $imagenurl = "/imagenes/";
         if ($request->tipo == 1) {
             $destinationPath = $path . "cabinas/";
             $imagenurl = $imagenurl . "cabinas/";
         } else {
             $destinationPath = $path . "clientes/";
             $imagenurl = $imagenurl . "clientes/";
         }
         if (!File::exists($destinationPath)) {
             File::makeDirectory($destinationPath);
         }
         $destinationPath = $destinationPath . $request->idrelacion . "/";
         $imagenurl = $imagenurl . $request->idrelacion . "/";
         foreach ($files as $file) {
             $extencion = $file->getClientOriginalExtension();
             $nombre = $file->getClientOriginalName();
             if (!File::exists($destinationPath)) {
                 File::makeDirectory($destinationPath);
             }
             $foto = Fotos::create(["nombre" => $nombre, "extencion" => $extencion]);
             $foto->imagenurl = $imagenurl . $foto->id . '.' . $extencion;
             $foto->imagenurlcompact = $imagenurl . $foto->id . 'compact.png';
             $foto->save();
             $file->move($destinationPath, $foto->id . '.' . $extencion);
             if ($request->tipo == 1) {
                 FotoCabina::create(["id_foto" => $foto->id, "id_cabina" => $request->idrelacion]);
             } else {
                 FotoCliente::create(["id_foto" => $foto->id, "id_cliente" => $request->idrelacion]);
             }
             try {
                 $image = Image::make($destinationPath . $foto->id . '.' . $extencion)->resize(150, 100)->save($destinationPath . $foto->id . 'compact.png');
             } catch (Exception $error) {
                 return "Las imagenes se subieron correctamente, Desea subir mas imagenes?";
             }
         }
         return "Las imagenes se subieron correctamente, Desea subir mas imagenes?";
     } else {
         return "No se ha seleccionado ninguna imagen" . $request->cabinaid;
     }
 }