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

Feat:user controller created and route name added for profile #42

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

alamriku
Copy link
Owner

No description provided.

@alamriku alamriku requested a review from me-shaon November 23, 2020 18:05
$this->middleware('auth');
}

public function profile($id){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSR coding style violation.
{ should be on the next line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it in other places too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

public function profile($id){
$user = User::where('id',$id)->first();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSR coding style violation.
where('id',$id), there should be a space after comma, like this: where('id', $id)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it in other places too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$this->middleware('auth');
}

public function profile($id){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than passing an id and querying to find the user with that id, just bind Route model here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

public function profileUpdate(Request $request){
$validator = Validator::make($request->all(),[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't write validation logic here. Create separate Request file with validation logic.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$profile->name=$request->name;
$profile->email=$request->email;
if($request->filled('password')){
dd('test');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-functioning, broken code.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return redirect()->back()->with('success','nothing updated');
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant empty lines.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$profile->password=$request->password;
}
$profile->update();
if($profile->wasChanged()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have this check.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1,7 +1,7 @@
<nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
<div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
<a class="navbar-brand brand-logo mr-5" href="index.html"><img src="images/logo.svg" class="mr-2" alt="logo"/></a>
<a class="navbar-brand brand-logo-mini" href="index.html"><img src="images/logo-mini.svg" alt="logo"/></a>
<a class="navbar-brand brand-logo mr-5" href="index.html"><img src="{{asset('asset')}}/images/logo.svg" class="mr-2" alt="logo"/></a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole image path should be inside asset method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

routes/web.php Outdated
@@ -21,4 +21,6 @@
return view('admin.dashboard');
})->middleware(['auth'])->name('dashboard');

Route::get('profile/{id}',[UserController::class,'profile'])->name('profile');
Route::put('profile-update',[UserController::class,'profileUpdate'])->name('profile-update');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route should be profile/update.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

routes/web.php Outdated
@@ -21,4 +21,6 @@
return view('admin.dashboard');
})->middleware(['auth'])->name('dashboard');

Route::get('profile/{id}',[UserController::class,'profile'])->name('profile');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the profile should be only for the 'logged in' user, no need to pass the user id here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

app/Http/Controllers/UserController.php Show resolved Hide resolved
app/Http/Controllers/UserController.php Show resolved Hide resolved
{
$users = User::paginate(5);
return view('user.list', compact('users'));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line after the method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public function profileUpdate(ProfileRequest $request)
{
$request->validated();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is wrong.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
public function index()
{
$users = User::paginate(5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode the paginate value here. Set it as a constant in a global 'Constant' file or in the Model.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -12,7 +12,8 @@ class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable,SoftDeletes;
const User ="User";
const Role="Role";
const Author="Author";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant should be ROLE_AUTHOR.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

routes/web.php Outdated
return view('admin.dashboard');
})->middleware(['auth'])->name('dashboard');

Route::get('profile/{user}',[UserController::class,'profile'])->name('profile');
Route::get('user/list',[UserController::class,'index'])->name('user-list');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route should be users.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

routes/web.php Outdated
return view('admin.dashboard');
})->middleware(['auth'])->name('dashboard');

Route::get('profile/{user}',[UserController::class,'profile'])->name('profile');
Route::get('user/list',[UserController::class,'index'])->name('user-list');
Route::delete('user/delete/{user}',[UserController::class,'destroy'])->name('user-delete');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route should be users/{user} with the DELETE method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

routes/web.php Outdated
Route::get('user/list',[UserController::class,'index'])->name('user-list');
Route::delete('user/delete/{user}',[UserController::class,'destroy'])->name('user-delete');
Route::put('profile/update',[UserController::class,'profileUpdate'])->name('profile-update');
Route::put('user/ban/{user}',[UserController::class,'Ban'])->name('ban-user');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route should be users/{user}/ban.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$profile->update();
return redirect()->back()->with('success','Profile updated');
}
public function Ban(User $user)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name shouldn't have Uppercase Letter at the beginning.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

use Notifiable;
use SoftDeletes;

public const USER = "User";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to ROLE_USER.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE


public const USER = "User";
public const ROLE_AUTHOR = "Author";
public const BANNED = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to STATUS_BANNED.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
$profile->update();
return redirect()->back()->with('success','Profile updated');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've missed this.

public function profile(User $user)
{
return view('profile', compact('user'));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line after the method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
public function profileUpdate(ProfileRequest $request)
{
$request->validated();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method call is redundant.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -72,4 +73,9 @@ public function changedReturnStatus()
{
return $this->hasMany(ReturnRequest::class,'status_changed_by');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've missed this.

use SoftDeletes;

public const USER = "User";
public const ROLE_AUTHOR = "Author";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be 'Librarian'? We don't have a 'Author' type user.

'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'role'=>User::User,
'phone'=>$this->faker->phoneNumber,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've missed this.

@php($i=1)
@foreach($users as $user)
<tr>
<th>{{$i++}}</th>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $loop->index instead of managing your own loop variable.

Copy link
Collaborator

@me-shaon me-shaon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Styling issues are not fixed yet.

@alamriku
Copy link
Owner Author

alamriku commented Dec 8, 2020

add an empty line after the method or the unused method are not removed?

@me-shaon
Copy link
Collaborator

me-shaon commented Dec 8, 2020

add an empty line after the method or the unused method are not removed?

Both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants