Exemplo n.º 1
0
 public function Planes($action = null)
 {
     if (isset($action)) {
         if ($action == "create") {
             $data = Planes::firstOrCreate(Input::except("_token", "_user"));
             return $respuesta = array('Record' => $data, 'Result' => "OK");
         }
         if ($action == "edit") {
             Planes::where("id", Input::get("id"))->update(Input::except("_token", "id", "_user"));
             return $respuesta = array('Record' => Planes::find(Input::get('id')), 'Result' => "OK");
         }
         if ($action == "remove") {
             Planes::where('id', Input::get("id"))->delete();
             return '{"Result":"OK"}';
         }
         if ($action == "list") {
             $Records = Planes::get();
             $respuesta = array('Records' => $Records, 'Result' => "OK");
             return json_encode($respuesta);
         }
         if ($action == "empresas") {
             $nulos = DB::table('empresas')->select(DB::raw("'NO POSEE' as DisplayText, NULL as Value"));
             $respuesta = DB::table('empresas')->select("nombre as DisplayText", "id as Value")->union($nulos)->orderby('value', 'asc')->distinct()->get();
             return "var opciones=" . json_encode($respuesta);
         }
     }
 }