Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Walter Felipe
pad-upe
Commits
86a4641e
Commit
86a4641e
authored
Apr 15, 2023
by
alissonalbuquerque
Browse files
feat(import/update_user): import file to update users from campus GARANHUNS
parent
a23c72a9
Changes
5
Show whitespace changes
Inline
Side-by-side
app/Http/Controllers/ImportUserController.php
0 → 100644
View file @
86a4641e
<?php
namespace
App\Http\Controllers
;
use
App\Models\Campus
;
use
App\Models\User
;
use
Illuminate\Http\Request
;
class
ImportUserController
extends
Controller
{
public
function
actionIndex
()
{
return
view
(
'imports.update_user'
);
}
public
function
actionStore
(
Request
$request
)
{
$file
=
$request
->
file
(
'uploadFile'
);
$handle
=
fopen
(
$file
,
'r'
);
$lines
=
[];
if
(
$handle
)
{
while
((
$data
=
fgetcsv
(
$handle
,
1000
,
","
))
!==
false
)
{
array_push
(
$lines
,
$data
);
}
}
unset
(
$lines
[
0
]);
$lines
=
array_map
(
function
(
$array
)
{
return
[
$array
[
1
],
$array
[
2
],
strtolower
(
trim
(
$array
[
7
]))];
},
$lines
);
$with_emails
=
array_filter
(
$lines
,
function
(
$array
)
{
return
$array
[
2
]
!==
'-'
;
});
$less_emails
=
array_filter
(
$lines
,
function
(
$array
)
{
return
$array
[
2
]
===
'-'
;
});
$campus_garanhuns
=
Campus
::
whereId
(
3
)
->
first
();
foreach
(
$with_emails
as
$data
)
{
$user
=
User
::
whereEmail
(
$data
[
2
])
->
first
();
$user
->
campus_id
=
$campus_garanhuns
->
id
;
if
(
!
$user
->
save
())
{
dd
(
'errors'
);
}
}
dd
(
$campus_garanhuns
,
$with_emails
,
$less_emails
);
fclose
(
$handle
);
return
redirect
()
->
route
(
'import_index'
);
}
}
app/Models/User.php
View file @
86a4641e
...
...
@@ -24,7 +24,7 @@ class User extends Authenticatable
* The attributes that are mass assignable.
* @var array<int, string>
*/
protected
$fillable
=
[
'name'
,
'email'
,
'password'
,
'status'
,
'c
urso
_id'
,
'c
ampus
_id'
,
'document'
];
protected
$fillable
=
[
'name'
,
'email'
,
'password'
,
'status'
,
'c
ampus
_id'
,
'c
urso
_id'
,
'document'
];
/**
* The attributes that should be hidden for serialization.
...
...
resources/views/imports/update_user.blade.php
0 → 100644
View file @
86a4641e
<h1>
Update Campus (Users)
</h1>
<form
action=
"{{route('import_store')}}"
method=
"post"
enctype=
"multipart/form-data"
>
@csrf
<input
type=
"file"
name=
"uploadFile"
id=
"uploadFile"
>
<button
type=
"submit"
>
Enviar
</button>
</form>
\ No newline at end of file
routes/import/update_user.php
0 → 100644
View file @
86a4641e
<?php
use
App\Http\Controllers\ImportUserController
;
use
Illuminate\Support\Facades\Route
;
Route
::
prefix
(
'/import'
)
->
group
(
function
()
{
Route
::
get
(
'/index'
,
[
ImportUserController
::
class
,
'actionIndex'
])
->
name
(
'import_index'
);
Route
::
post
(
'/store'
,
[
ImportUserController
::
class
,
'actionStore'
])
->
name
(
'import_store'
);
});
routes/web.php
View file @
86a4641e
...
...
@@ -46,6 +46,8 @@ require __DIR__ . '/dimensao/gestao.php';
require
__DIR__
.
'/dimensao/pesquisa.php'
;
require
__DIR__
.
'/dimensao/extensao.php'
;
require
__DIR__
.
'/import/update_user.php'
;
Route
::
get
(
'/'
,
function
()
{
return
redirect
()
->
route
(
'login'
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment