actually i try to migrate some users from a excel file (.xlsx) to login in my aplication. But the code doesn't work. The strange part is that the same code it's implemented for migrate payroll from a excel file (.xlsx) and this one work. I try many options, change some code, but it doesn't work. Maybe I'm letting some error out and someone else can see it. I would appreciate the help.
My ImportController.php from users
public function cargar_datos_users(Request $request)
{
$file= $request->file('file');
$original_name=$file->getClientOriginalName();
$r1=Storage::disk('files')->put($original_name, \File::get($file) );
$route= storage_path('files') ."/". $original_name;
if($r1)
{
Excel::selectSheetsByIndex(0)->load($route, function($sheet)
{
$sheet->each(function($row)
{
$user = new User;
$user->full_name = $row->nombreempleado;
$user->user = $row->empleado;
$user->password = bcrypt($row->empleado);
$perfil = 1;
$user->perfil = $perfil;
$user->save();
});
return view("administrator.contracts.adminpayrolls")->with("msj","Usuarios Cargados Correctamente");
}
else
{
return view("administrator.contracts.adminpayrolls")->with("msj","Error al subir el archivo");
}
}
My ImportController.php from payroll
public function cargar_datos_payrolls(Request $request)
{
$file= $request->file('file');
$original_name=$file->getClientOriginalName();
$r1=Storage::disk('files')->put($original_name, \File::get($file) );
$route= storage_path('files') ."/". $original_name;
if($r1)
{
Excel::selectSheetsByIndex(0)->load($route, function($sheet)
{
$sheet->each(function($row)
{
$payroll = new Payroll;
$payroll->lapso = $row->lapso;
$payroll->concept_payroll = $row->conceptonomina;
$payroll->payroll_concept_name = $row->nombreconceptonomina;
$payroll->id_employee = $row->empleado;
$payroll->hours = $row->horas;
$payroll->value = $row->valor;
$payroll->date_generation = $row->fechageneracion;
$payroll->date_from = $row->fechadesde;
$payroll->date_to = $row->fechahasta;
$payroll->balance_fee = $row->saldocuota;
$estado = 1;
$payroll->estado = $estado;
$payroll->save();
});
});
return view("administrator.contracts.adminpayrolls")->with("msj","Usuarios Cargados Correctamente");
}
else
{
return view("administrator.contracts.adminpayrolls")->with("msj","Error al subir el archivo");
}
}
My app/User.php
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
protected $table = 'users';
protected $fillable = ['full_name', 'user', 'password','perfil'];
protected $hidden = ['password', 'remember_token'];
}
The plugin for migrate from excel is http://ift.tt/1n2QXpH As I said, the same structure work on payroll migrate, but don't work on users migrate, any comments will be appreciate.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire