public function Calendar($action) { if (isset($action)) { if ($action == "create") { $evento = Eventos::firstOrCreate(Input::all()); foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } return $respuesta = array('Record' => $evento, 'Result' => "OK"); } if ($action == "edit") { $evento = Eventos::find(Input::get("id")); $evento->fill(Input::all()); $evento->save(); foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } return $respuesta = array('Record' => $evento, 'Result' => "OK"); } if ($action == "remove") { Eventos::where('id', Input::get("id"))->delete(); return '{"Result":"OK"}'; } if ($action == "list") { $Records = Eventos::get(); $Records->each(function ($evento) { foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } }); $respuesta = array('Records' => $Records, 'Result' => "OK"); return json_encode($respuesta); } if ($action == "areas") { $nulos = DB::table('areas')->select(DB::raw("'Ninguna' as DisplayText,'null' as value")); $respuesta = Areas::select("nombre as DisplayText", "id as Value")->union($nulos)->orderby('value', 'asc')->distinct()->get(); return "var opciones=" . json_encode($respuesta); } } }