Skip to content

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

Open
alamriku wants to merge 19 commits intodevelopfrom
auth
Open

Feat:user controller created and route name added for profile#42
alamriku wants to merge 19 commits intodevelopfrom
auth

Conversation

@alamriku
Copy link
Copy Markdown
Owner

No description provided.

@alamriku alamriku requested a review from me-shaon November 23, 2020 18:05
Comment thread app/Http/Controllers/UserController.php Outdated
$this->middleware('auth');
}

public function profile($id){
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
}

public function profile($id){
$user = User::where('id',$id)->first();
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
$this->middleware('auth');
}

public function profile($id){
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
}

public function profileUpdate(Request $request){
$validator = Validator::make($request->all(),[
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
$profile->name=$request->name;
$profile->email=$request->email;
if($request->filled('password')){
dd('test');
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
return redirect()->back()->with('success','nothing updated');
}


Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
$profile->password=$request->password;
}
$profile->update();
if($profile->wasChanged()){
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

<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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread routes/web.php Outdated
})->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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

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

Route::get('profile/{id}',[UserController::class,'profile'])->name('profile');
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php
Comment thread app/Http/Controllers/UserController.php
Comment thread app/Http/Controllers/UserController.php Outdated
{
$users = User::paginate(5);
return view('user.list', compact('users'));
}
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated

public function profileUpdate(ProfileRequest $request)
{
$request->validated();
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
}
public function index()
{
$users = User::paginate(5);
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Models/User.php Outdated
use HasFactory, Notifiable,SoftDeletes;
const User ="User";
const Role="Role";
const Author="Author";
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread routes/web.php Outdated
})->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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread routes/web.php Outdated

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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread 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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
$profile->update();
return redirect()->back()->with('success','Profile updated');
}
public function Ban(User $user)
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Models/User.php Outdated
use Notifiable;
use SoftDeletes;

public const USER = "User";
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

DONE

Comment thread app/Models/User.php Outdated

public const USER = "User";
public const ROLE_AUTHOR = "Author";
public const BANNED = 1;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Http/Controllers/UserController.php Outdated
}
public function profileUpdate(ProfileRequest $request)
{
$request->validated();
Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done

Comment thread app/Models/User.php
@@ -72,4 +73,9 @@ public function changedReturnStatus()
{
return $this->hasMany(ReturnRequest::class,'status_changed_by');
}
Copy link
Copy Markdown
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.

Comment thread app/Models/User.php Outdated
use SoftDeletes;

public const USER = "User";
public const ROLE_AUTHOR = "Author";
Copy link
Copy Markdown
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.

Comment thread database/factories/UserFactory.php Outdated
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'role'=>User::User,
'phone'=>$this->faker->phoneNumber,
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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