Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. Route::get("user_mig", function()
  2. {
  3. temporalestlaUser::truncate();
  4. $contr = temporalestlaContractUser::all();
  5. foreach ($contr as $value)
  6. {
  7. $psw = Hash::make($value->id_employee);
  8. $user = new temporalestlaUser
  9. ([
  10. "full_name"=>$value->name_used,
  11. "user" => $value->id_employee,
  12. "password" => $psw,
  13. "perfil" => 1
  14. ]);
  15. $user->save();
  16. }
  17. });
  18.  
  19. public function cargar_datos_users(Request $request)
  20. {
  21. $archivo = $request->file('archivo');
  22. $nombre_original=$archivo->getClientOriginalName();
  23. $extension=$archivo->getClientOriginalExtension();
  24. $r1=Storage::disk('archivos')->put($nombre_original, File::get($archivo) );
  25. $ruta = storage_path('archivos') ."/". $nombre_original;
  26. if($r1)
  27. {
  28. Excel::selectSheetsByIndex(0)->load($ruta, function($hoja)
  29. {
  30. $hoja->each(function($fila)
  31. {
  32. $pass = Hash::make($fila->empleado);
  33. $user = new User;
  34. $user->full_name = $fila->nombreempleado;
  35. $user->user = $fila->empleado;
  36. $user->password = $pass;
  37. $user->perfil = 1;
  38. $user->save();
  39. });
  40. });
  41. return view("administrator.contracts.adminpayrolls")->with("msj","Usuarios Cargados Correctamente");
  42. }
  43. else
  44. {
  45. return view("administrator.contracts.adminpayrolls")->with("msj","Error al subir el archivo");
  46. }
  47. }
  48.  
  49. class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
  50. {
  51. use Authenticatable, Authorizable, CanResetPassword;
  52.  
  53. protected $table = 'users';
  54.  
  55. protected $fillable = ['full_name', 'user', 'password','perfil'];
  56.  
  57. protected $hidden = ['password', 'remember_token'];
  58. }
  59.  
  60. <script type="text/javascript">
  61. $(document).on("submit",".formarchivo",function(e)
  62. {
  63. e.preventDefault();
  64. var formu=$(this);
  65. var nombreform=$(this).attr("id");
  66. if(nombreform=="f_cargar_datos_users" ){ var miurl="cargar_datos_users"; var divresul="notificacion_resul_fcdu"}
  67. var formData = new FormData($("#"+nombreform+"")[0]);
  68. $.ajax
  69. ({
  70. url: miurl,
  71. type: 'POST',
  72. data: formData,
  73. cache: false,
  74. contentType: false,
  75. processData: false,
  76. beforeSend: function()
  77. {
  78. $("#"+divresul+"").html($("#cargador_empresa").html());
  79. },
  80. success: function(data)
  81. {
  82. alert("Usuarios cargados correctamente");
  83. location.reload(true);
  84. },
  85. error: function(data)
  86. {
  87. alert("Error al subir usuarios. intente nuevamente");
  88. location.reload(true);
  89. }
  90. });
  91. });
  92. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement