Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/update 01 #4

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log

/public/js
/public/css
/public/fonts

public/js
public/fonts
public/css
public/mix-manifest.json
package-log.json
77 changes: 18 additions & 59 deletions app/Http/Controllers/System/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,22 @@

class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{

public function index(){
$users = User::get();
return view ('system.user.index', compact('users'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
public function create(){
$roles = Role::get();
return view('system.user.create', compact('roles'));
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(UserStoreRequest $request)
{
public function store(UserStoreRequest $request){
try {
$u = new User();
$u->email = $request->input('email');
$u->password = hash('sha256', $request->input('password'));
$u->password = hash('sha256', $request->input('password'));
$u->first_name = $request->input('first_name');
$u->last_name = $request->input('last_name');
$u->rol_id = $request->input('rol_id');
Expand All @@ -64,47 +46,25 @@ public function store(UserStoreRequest $request)
}
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
public function show($id){
$user = User::findOrFail($id);
return view('system.user.show', compact('user'));
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$user = User::findOrFail($id);
public function edit($id){
$user = User::findOrFail($id);
$roles = Role::get();
return view('system.user.edit',compact('user','roles'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
public function update(Request $request, $id){
try {
$u = User::findOrFail($id);
$u->email = $request->input('email');
$u->password = hash('sha256', $request->input('password'));
$u->first_name = $request->input('first_name');
$u->last_name = $request->input('last_name');
$u->rol_id = $request->input('rol_id');

if(!empty($request->file('photo'))){
$request->validate([
'photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
Expand All @@ -115,20 +75,19 @@ public function update(Request $request, $id)
$u->photo= $filename;
}
$u->update();
return redirect()->route('user.index')->with('success',trans('alert.update'));
return back()->with('success',trans('alert.update'));
} catch (\Throwable $th) {
return redirect()->route('user.index')->with('danger', trans('alert.danger'));
}
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
public function updatePassword(Request $request, $id){
$u = User::findOrFail($id);
$u->changePassword($request->input('password'));
return back()->with('success',trans('alert.update'));
}

public function destroy($id){
User::where('id',$id)->delete();
return redirect()->route('user.index')->with('success', trans('alert.delete'));
}
Expand Down
Loading