Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $this->command->info('Subir archivo asesores...');
     if (file_exists('public/temp/asesores.csv')) {
         if (($gestor = fopen('public/temp/asesores.csv', "r")) !== FALSE) {
             while (($vars = fgetcsv($gestor, 1000, ",")) !== FALSE) {
                 $cedula = $vars[0];
                 $nombre = $vars[1];
                 try {
                     \App\Asesor::create(['cedula' => $cedula, 'nombre' => $nombre]);
                 } catch (Exception $e) {
                 }
             }
             fclose($gestor);
             unlink('public/temp/asesores.csv');
         }
     }
 }
Пример #2
0
 public function crearAsesor(Request $request)
 {
     if ($request->ajax()) {
         try {
             $asesor = \App\Asesor::find($request['cedula']);
             if ($asesor == null) {
                 $asesor = \DB::select("select * from asesores where nombre = ?", [$request['nombre']]);
                 if (sizeof($asesor) == 0) {
                     \App\Asesor::create(['nombre' => $request['nombre'], 'cedula' => $request['cedula']]);
                     return 1;
                 } else {
                     return -2;
                 }
             } else {
                 return -1;
             }
         } catch (Exception $e) {
             return $e->getMessage();
         }
     }
 }