Skip to content

Commit

Permalink
User controller rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ttimot24 committed Sep 30, 2024
1 parent 9af7311 commit 7f7a005
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 45 deletions.
39 changes: 15 additions & 24 deletions app/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Controllers\Trait\UploadsImage;
use Illuminate\Http\Request;
use App\Libs\Controller;
use Illuminate\Routing\Controller;
use App\Model\User;

class UserController extends Controller
Expand Down Expand Up @@ -33,10 +33,7 @@ public function before()
*/
public function index()
{


$this->view->title(trans('user.users'));
return $this->view->render('users/index', [
return view('users.index', [
'all_users' => User::paginate($this->itemPerPage),
'active_users' => User::where('active', 1)->count(),
]);
Expand All @@ -49,10 +46,8 @@ public function index()
*/
public function create()
{

$this->view->title(trans('user.create_user'));
return $this->view->render('users/form', [
'current_user' => $this->request->user(),
return view('users.form', [
'current_user' => request()->user(),
'role_options' => \App\Model\UserRole::all()
]);
}
Expand All @@ -77,9 +72,9 @@ public function store(Request $request)

if ($user->save()) {

return $this->redirect(route("user.edit", ['user' => $user]))->withMessage(['success' => trans('message.successfully_created_user')]);
return redirect(route("user.edit", ['user' => $user]))->withMessage(['success' => trans('message.successfully_created_user')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand All @@ -91,9 +86,7 @@ public function store(Request $request)
*/
public function show(User $user)
{

$this->view->title(trans('user.view_user'));
return $this->view->render('users/view', [
return view('users.view', [
'user' => $user,
'previous_user' => User::where('id', '<', $user->id)->max('id'),
'next_user' => User::where('id', '>', $user->id)->min('id'),
Expand All @@ -108,10 +101,8 @@ public function show(User $user)
*/
public function edit(User $user)
{

$this->view->title(trans('user.edit_user'));
return $this->view->render('users/form', [
'current_user' => $this->request->user(),
return view('users.form', [
'current_user' => request()->user(),
'user' => $user,
'role_options' => \App\Model\UserRole::all(),
]);
Expand All @@ -137,9 +128,9 @@ public function update(Request $request, User $user)
$this->uploadImage($user);

if ($user->save()) {
return $this->redirect(route("user.edit", ['user' => $user]))->withMessage(['success' => trans('message.successfully_updated_user')]);
return redirect(route("user.edit", ['user' => $user]))->withMessage(['success' => trans('message.successfully_updated_user')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand All @@ -156,9 +147,9 @@ public function activate($id)
$user->active = 1;

if ($user->save()) {
return $this->redirectToSelf()->withMessage(['success' => trans('User successfully activated!')]);
return redirect()->back()->withMessage(['success' => trans('User successfully activated!')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand All @@ -173,10 +164,10 @@ public function destroy(User $user)
{

if ($user->delete()) {
return $this->redirect(route("user.index"))->withMessage(['success' => trans('message.successfully_deleted_user')]);
return redirect(route("user.index"))->withMessage(['success' => trans('message.successfully_deleted_user')]);
}


return $this->redirect(route("user.index"))->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect(route("user.index"))->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}
26 changes: 10 additions & 16 deletions app/Controllers/UserRoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
namespace App\Controllers;

use Illuminate\Http\Request;
use App\Libs\Controller;
use App\Http\Requests;
use Illuminate\Routing\Controller;
use App\Model\UserRole;

class UserRoleController extends Controller
{

public function index()
{

$this->view->title('User roles');
return $this->view->render('users/roles/index', [
return view('users.roles.index', [
'all_user_roles' => \App\Model\UserRole::all(),
'permission_list' => $this->getPermissionList(),
]);
Expand All @@ -27,10 +24,7 @@ public function index()
*/
public function create()
{


$this->view->title('Create role');
return $this->view->render('users/roles/create', [
return view('users.roles.create', [
'permission_list' => $this->getPermissionList(),
]);
}
Expand Down Expand Up @@ -80,9 +74,9 @@ public function store(Request $request)
$role->permission = 0;

if ($role->save()) {
return $this->redirect(route('userrole.index'))->withMessage(['success' => trans('User role created succesfully!')]);
return redirect(route('userrole.index'))->withMessage(['success' => trans('User role created succesfully!')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand Down Expand Up @@ -116,12 +110,12 @@ public function edit($id)
public function update(UserRole $userrole)
{

$userrole->rights = array_keys($this->request->except('_token'));
$userrole->rights = array_keys(request()->except('_token'));

if ($userrole->save()) {
return $this->redirectToSelf()->withMessage(['success' => trans('Rights saved succesfully!')]);
return redirect()->back()->withMessage(['success' => trans('Rights saved succesfully!')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand All @@ -135,9 +129,9 @@ public function destroy(UserRole $userrole)
{

if ($userrole->delete()) {
return $this->redirectToSelf()->withMessage(['success' => trans('User role deleted succesfully!')]);
return redirect()->back()->withMessage(['success' => trans('User role deleted succesfully!')]);
}

return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}
2 changes: 1 addition & 1 deletion app/View/users/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layout')
@extends('layout', ['title' => isset($user)? trans('user.edit_user') : trans('user.create_user')])

@section('content')
<div class='container main-container'>
Expand Down
2 changes: 1 addition & 1 deletion app/View/users/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layout')
@extends('layout', ['title' => trans('user.users')])

@section('content')
<div class='container main-container'>
Expand Down
2 changes: 1 addition & 1 deletion app/View/users/roles/create.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layout')
@extends('layout', ['title' => trans('Create role')])

@section('content')
<div class='container main-container'>
Expand Down
2 changes: 1 addition & 1 deletion app/View/users/roles/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layout')
@extends('layout', ['title' => trans('User roles')])

@section('content')
<div class='container main-container'>
Expand Down
2 changes: 1 addition & 1 deletion app/View/users/view.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('layout')
@extends('layout', ['title' => trans('user.view_user')])

@section('content')
<div class='container main-container'>
Expand Down

0 comments on commit 7f7a005

Please sign in to comment.