-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Conversation
$this->middleware('auth'); | ||
} | ||
|
||
public function profile($id){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(),[ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-functioning, broken code.
There was a problem hiding this comment.
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'); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant empty lines.
There was a problem hiding this comment.
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()){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
{ | ||
$users = User::paginate(5); | ||
return view('user.list', compact('users')); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is wrong.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/Models/User.php
Outdated
@@ -12,7 +12,8 @@ class User extends Authenticatable implements MustVerifyEmail | |||
{ | |||
use HasFactory, Notifiable,SoftDeletes; | |||
const User ="User"; | |||
const Role="Role"; | |||
const Author="Author"; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/Models/User.php
Outdated
use Notifiable; | ||
use SoftDeletes; | ||
|
||
public const USER = "User"; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
app/Models/User.php
Outdated
|
||
public const USER = "User"; | ||
public const ROLE_AUTHOR = "Author"; | ||
public const BANNED = 1; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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'); | ||
} |
There was a problem hiding this comment.
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')); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've missed this.
app/Models/User.php
Outdated
use SoftDeletes; | ||
|
||
public const USER = "User"; | ||
public const ROLE_AUTHOR = "Author"; |
There was a problem hiding this comment.
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.
database/factories/UserFactory.php
Outdated
'name' => $this->faker->name, | ||
'email' => $this->faker->unique()->safeEmail, | ||
'role'=>User::User, | ||
'phone'=>$this->faker->phoneNumber, |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
add an empty line after the method or the unused method are not removed? |
Both. |
No description provided.