/** * Store a newly created resource in storage. * * @return Response */ public function store(CrearCampRequest $request) { $camp = new Camp($request->all()); if (!($request->punts == "")) { //dd($request->poligon); $centre = GoogleMapsController::calcularCentrePoligon($request->punts); $arraycoords = GoogleMapsController::stringToArray($request->punts); //es forma el string per a insertar en mysql el linestring. Entre punt i //punt s'inserta una ',' excepte l'ultim punt (no es guarda si acaba en ',') $string = 'GeomFromText(\'LINESTRING('; for ($i = 0; $i < count($arraycoords); $i++) { $string = $string . $arraycoords[$i] . ' '; $i++; if (!($i < count($arraycoords) - 1)) { $string = $string . $arraycoords[$i]; } else { $string = $string . $arraycoords[$i] . ','; } } $string = $string . ')\')'; $camp->poligon = DB::raw($string); $camp->centre = DB::raw('PointFromText(\'POINT(' . $centre[0] . ' ' . $centre[1] . ')\')'); } $camp->user_profile_id = UserProfile::perfilId(Auth::user()->id); $camp->save(); return redirect('home/camp/' . $camp->id); }